[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
Török Edvin
edwin at clamav.net
Sun Apr 4 01:06:44 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit f7019d13e29b55329ab70018b2f32cf29393117e
Author: Török Edvin <edwin at clamav.net>
Date: Fri Oct 2 13:21:33 2009 +0300
Must free engine on exit, otherwise valgrind incorrectly reports leaks.
This occurs because the JIT stores pointers mangled (stores an integer in low
bits of the pointer), thus valgrind can't see that pointers to that memory
region still exist, and reports it as definetely lost, instead of still
reachable.
The fix is to always free the engine, even if this is the parent after the fork.
diff --git a/clamd/clamd.c b/clamd/clamd.c
index 2dd5708..1119c58 100644
--- a/clamd/clamd.c
+++ b/clamd/clamd.c
@@ -85,11 +85,24 @@ static void help(void)
}
static struct optstruct *opts;
-/* needs to be global, so that valgrind reports it as reachable, and not
- * as definetely/indirectly lost when daemonizing clamd */
-static struct cl_engine *engine = NULL;
+
+/* When running under valgrind and daemonizing, valgrind incorrectly reports
+ * leaks from the engine, because it can't see that all the memory is still
+ * reachable (some pointers are stored mangled in the JIT).
+ * So free the engine on exit from the parent too (during daemonize)
+ */
+static struct cl_engine *gengine = NULL;
+static void free_engine(void)
+{
+ if (gengine) {
+ cl_engine_free(gengine);
+ gengine = NULL;
+ }
+}
+
int main(int argc, char **argv)
{
+ static struct cl_engine *engine = NULL;
const struct optstruct *opt;
#ifndef C_WINDOWS
struct passwd *user = NULL;
@@ -444,11 +457,14 @@ int main(int argc, char **argv)
fcntl(lsockets[ret], F_SETFL, fcntl(lsockets[ret], F_GETFL) | O_NONBLOCK);
}
#endif
+ gengine = engine;
+ atexit(free_engine);
if(daemonize() == -1) {
logg("!daemonize() failed\n");
ret = 1;
break;
}
+ gengine = NULL;
#ifdef C_BSD
for(ret=0;ret<nlsockets;ret++) {
fcntl(lsockets[ret], F_SETFL, fcntl(lsockets[ret], F_GETFL) & ~O_NONBLOCK);
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list