Browse code

mpool debugging s/USE_MEMPOOL/USE_MPOOL/

git-svn: trunk@4329

Török Edvin authored on 2008/11/04 19:40:24
Showing 5 changed files
... ...
@@ -1,3 +1,9 @@
1
+Tue Nov  4 12:36:29 EET 2008 (edwin)
2
+------------------------------------
3
+ * libclamav/mpool.c, unit_tests/check_clamav.c,
4
+ unit_tests/check_matchers.c, unit_tests/check_regex.c: mpool
5
+ debugging s/USE_MEMPOOL/USE_MPOOL/
6
+
1 7
 Tue Nov  4 11:36:38 EET 2008 (edwin)
2 8
 ------------------------------------
3 9
  * clamd/thrmgr.c (thrmgr_printstats, IDLE_TASK): add comments
... ...
@@ -39,11 +39,16 @@
39 39
 #include <stddef.h>
40 40
 
41 41
 #include "others.h"
42
+#ifndef CL_DEBUG
43
+#define NDEBUG
44
+#endif
45
+#include <assert.h>
42 46
 
43
-/* #define DEBUGMPOOL /\* DO NOT define *\/ */
47
+#define MPOOLMAGIC 0x5adeada5
48
+/*#define DEBUGMPOOL /\* DO NOT define *\/ */
44 49
 #ifdef DEBUGMPOOL
45 50
 FILE *lfd = NULL;
46
-#define spam(...) cli_warnmsg(lfd, __VA_ARGS__)
51
+#define spam(...) cli_warnmsg( __VA_ARGS__)
47 52
 #else
48 53
 #define spam
49 54
 #endif
... ...
@@ -314,6 +319,9 @@ struct MP {
314 314
 struct FRAG {
315 315
   struct FRAG *next;
316 316
   unsigned int sbits;
317
+#ifdef CL_DEBUG
318
+  unsigned int magic;
319
+#endif
317 320
   void *fake;
318 321
 };
319 322
 #define FRAG_OVERHEAD (offsetof(struct FRAG, fake))
... ...
@@ -407,6 +415,9 @@ void *mp_malloc(struct MP *mp, size_t size) {
407 407
       spam("malloc %p size %u (hole)\n", f, roundup(size));
408 408
       mpm->usize += needed;
409 409
       f->sbits = sbits;
410
+#ifdef CL_DEBUG
411
+      f->magic = MPOOLMAGIC;
412
+#endif
410 413
       return &f->fake;
411 414
     }
412 415
     mpm = mpm->next;
... ...
@@ -430,6 +441,9 @@ void *mp_malloc(struct MP *mp, size_t size) {
430 430
   f = (struct FRAG *)((void *)mpm + align_to_voidptr(sizeof(*mpm)));
431 431
   spam("malloc %p size %u (new map)\n", f, roundup(size));
432 432
   f->sbits = sbits;
433
+#ifdef CL_DEBUG
434
+      f->magic = MPOOLMAGIC;
435
+#endif
433 436
   return &f->fake;
434 437
 }
435 438
 
... ...
@@ -437,6 +451,10 @@ void mp_free(struct MP *mp, void *ptr) {
437 437
   struct FRAG *f = (struct FRAG *)(ptr - FRAG_OVERHEAD);
438 438
   if (!ptr) return;
439 439
 
440
+#ifdef CL_DEBUG
441
+  assert(f->magic == MPOOLMAGIC && "Attempt to mp_free a pointer we did not allocate!");
442
+#endif
443
+
440 444
   f->next = mp->avail[f->sbits];
441 445
   mp->avail[f->sbits] = f;
442 446
   spam("free @ %p\n", f);
... ...
@@ -375,7 +375,7 @@ void diff_files(int fd, int ref_fd)
375 375
 	free(ref);
376 376
 }
377 377
 
378
-#ifdef USE_MEMPOOL
378
+#ifdef USE_MPOOL
379 379
 static mp_t *pool;
380 380
 #else
381 381
 static void *pool;
... ...
@@ -386,7 +386,7 @@ void dconf_setup(void)
386 386
 {
387 387
 	pool = NULL;
388 388
 	dconf = NULL;
389
-#ifdef USE_MEMPOOL
389
+#ifdef USE_MPOOL
390 390
 	pool = mp_create();
391 391
 	fail_unless(!!pool, "unable to create pool");
392 392
 #endif
... ...
@@ -397,7 +397,7 @@ void dconf_setup(void)
397 397
 void dconf_teardown(void)
398 398
 {
399 399
 	mp_free(pool, dconf);
400
-#ifdef USE_MEMPOOL
400
+#ifdef USE_MPOOL
401 401
 	if (pool)
402 402
 		mp_destroy(pool);
403 403
 #endif
... ...
@@ -61,7 +61,7 @@ START_TEST (test_ac_scanbuff) {
61 61
     fail_unless(root != NULL, "root == NULL");
62 62
     root->ac_only = 1;
63 63
 
64
-#ifdef USE_MEMPOOL
64
+#ifdef USE_MPOOL
65 65
     root->mempool = mp_create();
66 66
 #endif
67 67
     ret = cli_ac_init(root, AC_DEFAULT_MIN_DEPTH, AC_DEFAULT_MAX_DEPTH);
... ...
@@ -86,7 +86,7 @@ START_TEST (test_ac_scanbuff) {
86 86
 
87 87
     cli_ac_freedata(&mdata);
88 88
     cli_ac_free(root);
89
-#ifdef USE_MEMPOOL
89
+#ifdef USE_MPOOL
90 90
     mp_destroy(root->mempool);
91 91
 #endif
92 92
     free(root);
... ...
@@ -102,7 +102,7 @@ START_TEST (test_bm_scanbuff) {
102 102
     root = (struct cli_matcher *) cli_calloc(1, sizeof(struct cli_matcher));
103 103
     fail_unless(root != NULL, "root == NULL");
104 104
 
105
-#ifdef USE_MEMPOOL
105
+#ifdef USE_MPOOL
106 106
     root->mempool = mp_create();
107 107
 #endif
108 108
     ret = cli_bm_init(root);
... ...
@@ -119,7 +119,7 @@ START_TEST (test_bm_scanbuff) {
119 119
     fail_unless(ret == CL_VIRUS, "cli_bm_scanbuff() failed");
120 120
     fail_unless(!strncmp(virname, "Sig2", 4), "Incorrect signature matched in cli_bm_scanbuff()\n");
121 121
     cli_bm_free(root);
122
-#ifdef USE_MEMPOOL
122
+#ifdef USE_MPOOL
123 123
     mp_destroy(root->mempool);
124 124
 #endif
125 125
     free(root);
... ...
@@ -154,7 +154,7 @@ static struct regex_matcher matcher;
154 154
 static void rsetup(void)
155 155
 {
156 156
 	int rc;
157
-#ifdef USE_MEMPOOL
157
+#ifdef USE_MPOOL
158 158
 	matcher.mempool = mp_create();
159 159
 #endif
160 160
 	rc = init_regex_list(&matcher);
... ...
@@ -164,7 +164,7 @@ static void rsetup(void)
164 164
 static void rteardown(void)
165 165
 {
166 166
 	regex_list_done(&matcher);
167
-#ifdef USE_MEMPOOL
167
+#ifdef USE_MPOOL
168 168
 	mp_destroy(matcher.mempool);
169 169
 #endif
170 170
 }
... ...
@@ -280,15 +280,11 @@ static int loaded_2 = 0;
280 280
 static void psetup_impl(int load2)
281 281
 {
282 282
 	FILE *f;
283
-	struct phishcheck *pchk;
284 283
 	int rc;
285
-	rc = cli_initengine(&engine, 0);
284
+	rc = cli_initengine(&engine, CL_DB_STDOPT);
286 285
 	fail_unless(rc == 0, "cl_initengine");
287 286
 
288
-	rc = phishing_init(engine);
289
-	fail_unless(rc == 0,"phishing_init");
290
-	pchk = engine->phishcheck;
291
-	fail_unless(!!pchk, "engine->phishcheck");
287
+	fail_unless(!!engine->phishcheck, "engine->phishcheck");
292 288
 
293 289
 	rc = init_domainlist(engine);
294 290
 	fail_unless(rc == 0,"init_domainlist");