From 395fb661e351e693875f6f912c11ceb8a6eeb0f4 Mon Sep 17 00:00:00 2001 From: Tomasz Kojm Date: Wed, 12 Nov 2008 19:39:31 +0000 Subject: [PATCH] fix some possible memleaks git-svn: trunk@4391 --- clamd/clamd.c | 1 + clamd/server-th.c | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/clamd/clamd.c b/clamd/clamd.c index 07f715d32..7f6456e41 100644 --- a/clamd/clamd.c +++ b/clamd/clamd.c @@ -363,6 +363,7 @@ int main(int argc, char **argv) logg("!Can't allocate memory for pua_cats\n"); logg_close(); freecfg(copt); + cl_engine_free(engine); return 1; } logg("# %s", cpt->strarg); diff --git a/clamd/server-th.c b/clamd/server-th.c index 91efb64b4..011ca9ef4 100644 --- a/clamd/server-th.c +++ b/clamd/server-th.c @@ -215,6 +215,16 @@ static struct cl_engine *reload_db(struct cl_engine *engine, unsigned int dbopti } } + /* release old structure */ + if(engine) { + if(dboptions & (CL_DB_PUA_INCLUDE | CL_DB_PUA_EXCLUDE)) + if(cl_engine_get(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats)) + logg("^Can't make a copy of pua_cats\n"); + + thrmgr_setactiveengine(NULL); + cl_engine_free(engine); + } + dbdir = cfgopt(copt, "DatabaseDirectory")->strarg; logg("Reading databases from %s\n", dbdir); @@ -236,16 +246,6 @@ static struct cl_engine *reload_db(struct cl_engine *engine, unsigned int dbopti return NULL; } - /* release old structure */ - if(engine) { - if(dboptions & (CL_DB_PUA_INCLUDE | CL_DB_PUA_EXCLUDE)) - if(cl_engine_get(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats)) - logg("^Can't make a copy of pua_cats\n"); - - thrmgr_setactiveengine(NULL); - cl_engine_free(engine); - } - if(!(engine = cl_engine_new(CL_ENGINE_DEFAULT))) { logg("!Can't initialize antivirus engine\n"); *ret = 1; @@ -253,11 +253,12 @@ static struct cl_engine *reload_db(struct cl_engine *engine, unsigned int dbopti } if(strlen(pua_cats)) { - if((retval = cl_engine_set(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) + if((retval = cl_engine_set(engine, CL_ENGINE_PUA_CATEGORIES, pua_cats))) { logg("!cl_engine_set(CL_ENGINE_PUA_CATEGORIES): %s\n", cl_strerror(retval)); - cl_engine_free(engine); - *ret = 1; - return NULL; + cl_engine_free(engine); + *ret = 1; + return NULL; + } } if((retval = cl_load(dbdir, engine, &sigs, dboptions))) {