Browse code

clambc should create an engine too.

Török Edvin authored on 2010/05/14 17:09:34
Showing 1 changed files
... ...
@@ -325,10 +325,20 @@ int main(int argc, char *argv[])
325 325
         print_src(opts->filename[0]);
326 326
     } else {
327 327
 	cli_ctx cctx;
328
-	struct cl_engine engine;
328
+	struct cl_engine *engine = cl_engine_new();
329 329
 	fmap_t *map = NULL;
330 330
 	memset(&cctx, 0, sizeof(cctx));
331
-	memset(&engine, 0, sizeof(engine));
331
+	if (!engine) {
332
+	    fprintf(stderr,"Unable to create engine\n");
333
+	    optfree(opts);
334
+	    exit(3);
335
+	}
336
+	rc = cl_engine_compile(engine);
337
+	if (rc) {
338
+	    fprintf(stderr,"Unable to compile engine: %s\n", cl_strerror(rc));
339
+	    optfree(opts);
340
+	    exit(4);
341
+	}
332 342
 	rc = cli_bytecode_prepare(&bcs, BYTECODE_ENGINE_MASK);
333 343
 	if (rc != CL_SUCCESS) {
334 344
 	    fprintf(stderr,"Unable to prepare bytecode: %s\n", cl_strerror(rc));
... ...
@@ -344,7 +354,12 @@ int main(int argc, char *argv[])
344 344
 	    exit(3);
345 345
 	}
346 346
 	ctx->ctx = &cctx;
347
-	cctx.engine = &engine;
347
+	cctx.engine = engine;
348
+	cctx.fmap = cli_calloc(sizeof(fmap_t*), engine->maxreclevel+2);
349
+	if (!cctx.fmap) {
350
+	    fprintf(stderr,"Out of memory\n");
351
+	    exit(3);
352
+	}
348 353
 	memset(&dbg_state, 0, sizeof(dbg_state));
349 354
 	dbg_state.file = "<libclamav>";
350 355
 	dbg_state.line = 0;
... ...
@@ -411,6 +426,8 @@ int main(int argc, char *argv[])
411 411
 	cli_bytecode_context_destroy(ctx);
412 412
 	if (map)
413 413
 	    funmap(map);
414
+	cl_engine_free(engine);
415
+	free(cctx.fmap);
414 416
     }
415 417
     cli_bytecode_destroy(bc);
416 418
     cli_bytecode_done(&bcs);