[cvs] SF.net SVN: bogofilter:[7044] trunk/bogofilter
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <m-...@us...> - 2016-01-26 01:20:49
|
Revision: 7044 http://sourceforge.net/p/bogofilter/code/7044 Author: m-a Date: 2016-01-26 01:20:47 +0000 (Tue, 26 Jan 2016) Log Message: ----------- Apply patch from Denny Lin to plug a few memory leaks in the TokyoCabinet implementation, contributed through the bogofilter-dev mailing list. Thanks! Modified Paths: -------------- trunk/bogofilter/NEWS trunk/bogofilter/configure.ac trunk/bogofilter/src/datastore_tc.c Modified: trunk/bogofilter/NEWS =================================================================== --- trunk/bogofilter/NEWS 2016-01-25 23:17:32 UTC (rev 7043) +++ trunk/bogofilter/NEWS 2016-01-26 01:20:47 UTC (rev 7044) @@ -15,6 +15,12 @@ ------------------------------------------------------------------------------- + 2016-01-26 + + * Apply patch from Denny Lin to plug a few memory leaks in the + TokyoCabinet implementation contributed through the bogofilter-dev + mailing list. Thanks! + 2015-10-10 * Fix build with C89 compilers. Modified: trunk/bogofilter/configure.ac =================================================================== --- trunk/bogofilter/configure.ac 2016-01-25 23:17:32 UTC (rev 7043) +++ trunk/bogofilter/configure.ac 2016-01-26 01:20:47 UTC (rev 7044) @@ -493,10 +493,8 @@ LIBS="$LIBS $LIBDB" AC_LINK_IFELSE([AC_LANG_PROGRAM([ #include <tcutil.h> -#include <tchdb.h> #include <tcbdb.h> #include <stdlib.h> -#include <time.h> #include <stdbool.h> #include <stdint.h> ], [ Modified: trunk/bogofilter/src/datastore_tc.c =================================================================== --- trunk/bogofilter/src/datastore_tc.c 2016-01-25 23:17:32 UTC (rev 7043) +++ trunk/bogofilter/src/datastore_tc.c 2016-01-26 01:20:47 UTC (rev 7044) @@ -16,10 +16,8 @@ #include "common.h" #include <tcutil.h> -#include <tchdb.h> #include <tcbdb.h> #include <stdlib.h> -#include <time.h> #include <stdbool.h> #include <stdint.h> @@ -33,9 +31,7 @@ #define UNUSED(x) ((void)&x) typedef struct { - char *path; char *name; - bool locked; bool created; TCBDB *dbp; } dbh_t; @@ -121,9 +117,8 @@ memset(handle, 0, sizeof(dbh_t)); /* valgrind */ handle->name = xstrdup(bfp->filepath); - - handle->locked = false; handle->created = false; + handle->dbp = tcbdbnew(); return handle; } @@ -133,7 +128,7 @@ { if (handle != NULL) { xfree(handle->name); - xfree(handle->path); + tcbdbdel(handle->dbp); xfree(handle); } return; @@ -180,7 +175,7 @@ if (handle == NULL) return NULL; - dbp = handle->dbp = tcbdbnew(); + dbp = handle->dbp; res = tcbdbopen(dbp, handle->name, open_flags); if (!res && (open_mode & DS_WRITE)) { res = tcbdbopen(dbp, handle->name, open_flags | BDBOCREAT); @@ -318,9 +313,6 @@ handle->name, tcbdbecode(dbp), tcbdberrmsg(tcbdbecode(dbp))); - tcbdbdel(dbp); - handle->dbp = NULL; - dbh_free(handle); } @@ -352,37 +344,36 @@ char *key, *data; cursor = tcbdbcurnew(dbp); - ret = tcbdbcurfirst(cursor); - if (ret) { - while ((key = tcbdbcurkey(cursor, &ksiz))) { - data = tcbdbcurval(cursor, &dsiz); - if (data) { - /* switch to "dbv_t *" variables */ - dbv_key.leng = ksiz; - dbv_key.data = xmalloc(dbv_key.leng+1); - memcpy(dbv_key.data, key, ksiz); - ((char *)dbv_key.data)[dbv_key.leng] = '\0'; + if (!tcbdbcurfirst(cursor)) { + print_error(__FILE__, __LINE__, "(tc) tcbdbcurfirst err: %d, %s", + tcbdbecode(dbp), tcbdberrmsg(tcbdbecode(dbp))); + exit(EX_ERROR); + } - dbv_data.data = data; - dbv_data.leng = dsiz; /* read count */ + while ((key = tcbdbcurkey(cursor, &ksiz))) { + data = tcbdbcurval(cursor, &dsiz); + if (data) { + /* switch to "dbv_t *" variables */ + dbv_key.data = xstrdup(key); + dbv_key.leng = ksiz; - /* call user function */ - ret = hook(&dbv_key, &dbv_data, userdata); + dbv_data.data = data; + dbv_data.leng = dsiz; /* read count */ - xfree(dbv_key.data); + /* call user function */ + ret = hook(&dbv_key, &dbv_data, userdata); - if (ret != 0) - break; - free(data); /* not xfree() as allocated by dpget() */ + xfree(dbv_key.data); + free(data); /* not xfree() as allocated by dpget() */ + + if (ret != 0) { + free(key); + break; } - free(key); /* not xfree() as allocated by dpiternext() */ + } + free(key); /* not xfree() as allocated by dpiternext() */ - tcbdbcurnext(cursor); - } - } else { - print_error(__FILE__, __LINE__, "(tc) tcbdbcurfirst err: %d, %s", - tcbdbecode(dbp), tcbdberrmsg(tcbdbecode(dbp))); - exit(EX_ERROR); + tcbdbcurnext(cursor); } tcbdbcurdel(cursor); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |