mpool debugging

s/USE_MEMPOOL/USE_MPOOL/

git-svn: trunk@4329
0.95
Török Edvin 17 years ago
parent 764f76c841
commit 7866b37c6b
  1. 6
      ChangeLog
  2. 22
      libclamav/mpool.c
  3. 6
      unit_tests/check_clamav.c
  4. 8
      unit_tests/check_matchers.c
  5. 12
      unit_tests/check_regex.c

@ -1,3 +1,9 @@
Tue Nov 4 12:36:29 EET 2008 (edwin)
------------------------------------
* libclamav/mpool.c, unit_tests/check_clamav.c,
unit_tests/check_matchers.c, unit_tests/check_regex.c: mpool
debugging s/USE_MEMPOOL/USE_MPOOL/
Tue Nov 4 11:36:38 EET 2008 (edwin)
------------------------------------
* clamd/thrmgr.c (thrmgr_printstats, IDLE_TASK): add comments

@ -39,11 +39,16 @@
#include <stddef.h>
#include "others.h"
#ifndef CL_DEBUG
#define NDEBUG
#endif
#include <assert.h>
/* #define DEBUGMPOOL /\* DO NOT define *\/ */
#define MPOOLMAGIC 0x5adeada5
/*#define DEBUGMPOOL /\* DO NOT define *\/ */
#ifdef DEBUGMPOOL
FILE *lfd = NULL;
#define spam(...) cli_warnmsg(lfd, __VA_ARGS__)
#define spam(...) cli_warnmsg( __VA_ARGS__)
#else
#define spam
#endif
@ -314,6 +319,9 @@ struct MP {
struct FRAG {
struct FRAG *next;
unsigned int sbits;
#ifdef CL_DEBUG
unsigned int magic;
#endif
void *fake;
};
#define FRAG_OVERHEAD (offsetof(struct FRAG, fake))
@ -407,6 +415,9 @@ void *mp_malloc(struct MP *mp, size_t size) {
spam("malloc %p size %u (hole)\n", f, roundup(size));
mpm->usize += needed;
f->sbits = sbits;
#ifdef CL_DEBUG
f->magic = MPOOLMAGIC;
#endif
return &f->fake;
}
mpm = mpm->next;
@ -430,6 +441,9 @@ void *mp_malloc(struct MP *mp, size_t size) {
f = (struct FRAG *)((void *)mpm + align_to_voidptr(sizeof(*mpm)));
spam("malloc %p size %u (new map)\n", f, roundup(size));
f->sbits = sbits;
#ifdef CL_DEBUG
f->magic = MPOOLMAGIC;
#endif
return &f->fake;
}
@ -437,6 +451,10 @@ void mp_free(struct MP *mp, void *ptr) {
struct FRAG *f = (struct FRAG *)(ptr - FRAG_OVERHEAD);
if (!ptr) return;
#ifdef CL_DEBUG
assert(f->magic == MPOOLMAGIC && "Attempt to mp_free a pointer we did not allocate!");
#endif
f->next = mp->avail[f->sbits];
mp->avail[f->sbits] = f;
spam("free @ %p\n", f);

@ -375,7 +375,7 @@ void diff_files(int fd, int ref_fd)
free(ref);
}
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
static mp_t *pool;
#else
static void *pool;
@ -386,7 +386,7 @@ void dconf_setup(void)
{
pool = NULL;
dconf = NULL;
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
pool = mp_create();
fail_unless(!!pool, "unable to create pool");
#endif
@ -397,7 +397,7 @@ void dconf_setup(void)
void dconf_teardown(void)
{
mp_free(pool, dconf);
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
if (pool)
mp_destroy(pool);
#endif

@ -61,7 +61,7 @@ START_TEST (test_ac_scanbuff) {
fail_unless(root != NULL, "root == NULL");
root->ac_only = 1;
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
root->mempool = mp_create();
#endif
ret = cli_ac_init(root, AC_DEFAULT_MIN_DEPTH, AC_DEFAULT_MAX_DEPTH);
@ -86,7 +86,7 @@ START_TEST (test_ac_scanbuff) {
cli_ac_freedata(&mdata);
cli_ac_free(root);
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
mp_destroy(root->mempool);
#endif
free(root);
@ -102,7 +102,7 @@ START_TEST (test_bm_scanbuff) {
root = (struct cli_matcher *) cli_calloc(1, sizeof(struct cli_matcher));
fail_unless(root != NULL, "root == NULL");
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
root->mempool = mp_create();
#endif
ret = cli_bm_init(root);
@ -119,7 +119,7 @@ START_TEST (test_bm_scanbuff) {
fail_unless(ret == CL_VIRUS, "cli_bm_scanbuff() failed");
fail_unless(!strncmp(virname, "Sig2", 4), "Incorrect signature matched in cli_bm_scanbuff()\n");
cli_bm_free(root);
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
mp_destroy(root->mempool);
#endif
free(root);

@ -154,7 +154,7 @@ static struct regex_matcher matcher;
static void rsetup(void)
{
int rc;
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
matcher.mempool = mp_create();
#endif
rc = init_regex_list(&matcher);
@ -164,7 +164,7 @@ static void rsetup(void)
static void rteardown(void)
{
regex_list_done(&matcher);
#ifdef USE_MEMPOOL
#ifdef USE_MPOOL
mp_destroy(matcher.mempool);
#endif
}
@ -280,15 +280,11 @@ static int loaded_2 = 0;
static void psetup_impl(int load2)
{
FILE *f;
struct phishcheck *pchk;
int rc;
rc = cli_initengine(&engine, 0);
rc = cli_initengine(&engine, CL_DB_STDOPT);
fail_unless(rc == 0, "cl_initengine");
rc = phishing_init(engine);
fail_unless(rc == 0,"phishing_init");
pchk = engine->phishcheck;
fail_unless(!!pchk, "engine->phishcheck");
fail_unless(!!engine->phishcheck, "engine->phishcheck");
rc = init_domainlist(engine);
fail_unless(rc == 0,"init_domainlist");

Loading…
Cancel
Save