git-svn-id: file:///var/lib/svn/clamav-devel/branches/mpool@4280 77e5149b-7576-45b1-b177-96237e5ba77b
aCaB authored on 2008/10/20 01:16:49... | ... |
@@ -100,16 +100,22 @@ cli_file_t cli_ftcode(const char *name) |
100 | 100 |
return CL_TYPE_ERROR; |
101 | 101 |
} |
102 | 102 |
|
103 |
-void cli_ftfree(struct cli_ftype *ftypes) |
|
103 |
+void cli_ftfree(const struct cl_engine *engine) |
|
104 | 104 |
{ |
105 |
- struct cli_ftype *pt; |
|
105 |
+ struct cli_ftype *ftypes=engine->ftypes, *pt; |
|
106 | 106 |
|
107 | 107 |
while(ftypes) { |
108 | 108 |
pt = ftypes; |
109 | 109 |
ftypes = ftypes->next; |
110 |
+#ifdef USE_MPOOL |
|
111 |
+ mpool_free(engine->mempool, pt->magic); |
|
112 |
+ mpool_free(engine->mempool, pt->tname); |
|
113 |
+ mpool_free(engine->mempool, pt); |
|
114 |
+#else |
|
110 | 115 |
free(pt->magic); |
111 | 116 |
free(pt->tname); |
112 | 117 |
free(pt); |
118 |
+#endif |
|
113 | 119 |
} |
114 | 120 |
} |
115 | 121 |
|
... | ... |
@@ -95,7 +95,7 @@ struct cli_matched_type { |
95 | 95 |
}; |
96 | 96 |
|
97 | 97 |
cli_file_t cli_ftcode(const char *name); |
98 |
-void cli_ftfree(struct cli_ftype *ftypes); |
|
98 |
+void cli_ftfree(const struct cl_engine *engine); |
|
99 | 99 |
cli_file_t cli_filetype(const unsigned char *buf, size_t buflen, const struct cl_engine *engine); |
100 | 100 |
cli_file_t cli_filetype2(int desc, const struct cl_engine *engine); |
101 | 101 |
int cli_addtypesigs(struct cl_engine *engine); |
... | ... |
@@ -406,8 +406,16 @@ void cli_ac_free(struct cli_matcher *root) |
406 | 406 |
|
407 | 407 |
for(i = 0; i < root->ac_patterns; i++) { |
408 | 408 |
patt = root->ac_pattable[i]; |
409 |
+#ifdef USE_MPOOL |
|
410 |
+ patt->prefix ? mpool_free(root->mempool, patt->prefix) : mpool_free(root->mempool, patt->pattern); |
|
411 |
+#else |
|
409 | 412 |
patt->prefix ? free(patt->prefix) : free(patt->pattern); |
413 |
+#endif |
|
414 |
+#ifdef USE_MPOOL |
|
415 |
+ mpool_free(root->mempool, patt->virname); |
|
416 |
+#else |
|
410 | 417 |
free(patt->virname); |
418 |
+#endif |
|
411 | 419 |
if(patt->offset) |
412 | 420 |
#ifdef USE_MPOOL |
413 | 421 |
mpool_free(root->mempool, patt->offset); |
... | ... |
@@ -420,23 +428,45 @@ void cli_ac_free(struct cli_matcher *root) |
420 | 420 |
#else |
421 | 421 |
ac_free_alt(patt); |
422 | 422 |
#endif |
423 |
+#ifdef USE_MPOOL |
|
424 |
+ mpool_free(root->mempool, patt); |
|
425 |
+ |
|
426 |
+#else |
|
423 | 427 |
free(patt); |
428 |
+#endif |
|
424 | 429 |
} |
425 | 430 |
if(root->ac_pattable) |
431 |
+#ifdef USE_MPOOL |
|
432 |
+ mpool_free(root->mempool, root->ac_pattable); |
|
433 |
+#else |
|
426 | 434 |
free(root->ac_pattable); |
435 |
+#endif |
|
427 | 436 |
|
428 | 437 |
for(i = 0; i < root->ac_nodes; i++) { |
429 | 438 |
if(!root->ac_nodetable[i]->leaf) |
439 |
+#ifdef USE_MPOOL |
|
440 |
+ mpool_free(root->mempool, root->ac_nodetable[i]->trans); |
|
441 |
+ mpool_free(root->mempool, root->ac_nodetable[i]); |
|
442 |
+#else |
|
430 | 443 |
free(root->ac_nodetable[i]->trans); |
431 | 444 |
free(root->ac_nodetable[i]); |
445 |
+#endif |
|
432 | 446 |
} |
433 | 447 |
|
434 | 448 |
if(root->ac_nodetable) |
449 |
+#ifdef USE_MPOOL |
|
450 |
+ mpool_free(root->mempool, root->ac_nodetable); |
|
451 |
+#else |
|
435 | 452 |
free(root->ac_nodetable); |
436 |
- |
|
453 |
+#endif |
|
437 | 454 |
if(root->ac_root) { |
455 |
+#ifdef USE_MPOOL |
|
456 |
+ mpool_free(root->mempool, root->ac_root->trans); |
|
457 |
+ mpool_free(root->mempool, root->ac_root); |
|
458 |
+#else |
|
438 | 459 |
free(root->ac_root->trans); |
439 | 460 |
free(root->ac_root); |
461 |
+#endif |
|
440 | 462 |
} |
441 | 463 |
} |
442 | 464 |
|
... | ... |
@@ -108,7 +108,11 @@ int cli_bm_init(struct cli_matcher *root) |
108 | 108 |
#endif |
109 | 109 |
return CL_EMEM; |
110 | 110 |
|
111 |
+#ifdef USE_MPOOL |
|
112 |
+ if(!(root->bm_suffix = (struct cli_bm_patt **) mpool_calloc(root->mempool, size, sizeof(struct cli_bm_patt *), NULL))) { |
|
113 |
+#else |
|
111 | 114 |
if(!(root->bm_suffix = (struct cli_bm_patt **) cli_calloc(size, sizeof(struct cli_bm_patt *)))) { |
115 |
+#endif |
|
112 | 116 |
#ifdef USE_MPOOL |
113 | 117 |
mpool_free(root->mempool, root->bm_shift); |
114 | 118 |
#else |
... | ... |
@@ -130,7 +134,11 @@ void cli_bm_free(struct cli_matcher *root) |
130 | 130 |
|
131 | 131 |
|
132 | 132 |
if(root->bm_shift) |
133 |
+#ifdef USE_MPOOL |
|
134 |
+ mpool_free(root->mempool, root->bm_shift); |
|
135 |
+#else |
|
133 | 136 |
free(root->bm_shift); |
137 |
+#endif |
|
134 | 138 |
|
135 | 139 |
if(root->bm_suffix) { |
136 | 140 |
for(i = 0; i < size; i++) { |
... | ... |
@@ -139,17 +147,42 @@ void cli_bm_free(struct cli_matcher *root) |
139 | 139 |
prev = patt; |
140 | 140 |
patt = patt->next; |
141 | 141 |
if(prev->prefix) |
142 |
+#ifdef USE_MPOOL |
|
143 |
+ mpool_free(root->mempool, prev->prefix); |
|
144 |
+#else |
|
142 | 145 |
free(prev->prefix); |
146 |
+#endif |
|
143 | 147 |
else |
148 |
+#ifdef USE_MPOOL |
|
149 |
+ mpool_free(root->mempool, prev->pattern); |
|
150 |
+#else |
|
144 | 151 |
free(prev->pattern); |
152 |
+#endif |
|
145 | 153 |
if(prev->virname) |
154 |
+#ifdef USE_MPOOL |
|
155 |
+ mpool_free(root->mempool, prev->virname); |
|
156 |
+#else |
|
146 | 157 |
free(prev->virname); |
158 |
+#endif |
|
147 | 159 |
if(prev->offset) |
160 |
+#ifdef USE_MPOOL |
|
161 |
+ mpool_free(root->mempool, prev->offset); |
|
162 |
+#else |
|
148 | 163 |
free(prev->offset); |
164 |
+#endif |
|
165 |
+#ifdef USE_MPOOL |
|
166 |
+ mpool_free(root->mempool, prev); |
|
167 |
+#else |
|
149 | 168 |
free(prev); |
169 |
+#endif |
|
170 |
+ |
|
150 | 171 |
} |
151 | 172 |
} |
173 |
+#ifdef USE_MPOOL |
|
174 |
+ mpool_free(root->mempool, root->bm_suffix); |
|
175 |
+#else |
|
152 | 176 |
free(root->bm_suffix); |
177 |
+#endif |
|
153 | 178 |
} |
154 | 179 |
} |
155 | 180 |
|
... | ... |
@@ -58,6 +58,9 @@ struct cli_lsig_tdb { |
58 | 58 |
const uint32_t *engine, *nos, *ep; |
59 | 59 |
const uint32_t *sectoff, *sectrva, *sectvsz, *sectraw, *sectrsz, |
60 | 60 |
*secturva, *sectuvsz, *secturaw, *sectursz; |
61 |
+#ifdef USE_MPOOL |
|
62 |
+ mpool_t *mempool; |
|
63 |
+#endif |
|
61 | 64 |
}; |
62 | 65 |
|
63 | 66 |
struct cli_ac_lsig { |
... | ... |
@@ -789,6 +789,7 @@ static void *alloc_mem(mpool_t *mp_p, const unsigned long byte_size, |
789 | 789 |
} |
790 | 790 |
|
791 | 791 |
SET_POINTER(error_p, MPOOL_ERROR_NONE); |
792 |
+ // printf("^alloc'd %p::%p(%u)\n", mp_p, addr, byte_size); |
|
792 | 793 |
return addr; |
793 | 794 |
} |
794 | 795 |
|
... | ... |
@@ -819,6 +820,8 @@ static int free_mem(mpool_t *mp_p, void *addr, const unsigned long size) |
819 | 819 |
unsigned long old_size, fence; |
820 | 820 |
int ret; |
821 | 821 |
mpool_block_t *block_p; |
822 |
+ |
|
823 |
+ // printf("free'd %p::%p(%u)\n", mp_p, addr, size); |
|
822 | 824 |
|
823 | 825 |
/* |
824 | 826 |
* If the size is larger than a block then the allocation must be at |
... | ... |
@@ -862,7 +865,6 @@ static int free_mem(mpool_t *mp_p, void *addr, const unsigned long size) |
862 | 862 |
|
863 | 863 |
/* adjust our stats */ |
864 | 864 |
mp_p->mp_alloc_c--; |
865 |
- |
|
866 | 865 |
return MPOOL_ERROR_NONE; |
867 | 866 |
} |
868 | 867 |
|
... | ... |
@@ -1494,6 +1496,17 @@ void *mpool_resize(mpool_t *mp_p, void *old_addr, |
1494 | 1494 |
return &new_frag->frag_ptr; |
1495 | 1495 |
} |
1496 | 1496 |
|
1497 |
+ |
|
1498 |
+void *mpool_resize2(mpool_t *mp_p, void *old_addr, |
|
1499 |
+ const unsigned long new_byte_size, |
|
1500 |
+ int *error_p) |
|
1501 |
+{ |
|
1502 |
+ void *alloc = mpool_resize(mp_p, old_addr, new_byte_size, error_p); |
|
1503 |
+ if(!alloc && old_addr) |
|
1504 |
+ mpool_free(mp_p, old_addr); |
|
1505 |
+ return alloc; |
|
1506 |
+} |
|
1507 |
+ |
|
1497 | 1508 |
/* |
1498 | 1509 |
* int mpool_stats |
1499 | 1510 |
* |
... | ... |
@@ -343,6 +343,10 @@ extern |
343 | 343 |
void *mpool_resize(mpool_t *mp_p, void *old_addr, |
344 | 344 |
const unsigned long new_byte_size, |
345 | 345 |
int *error_p); |
346 |
+extern |
|
347 |
+void *mpool_resize2(mpool_t *mp_p, void *old_addr, |
|
348 |
+ const unsigned long new_byte_size, |
|
349 |
+ int *error_p); |
|
346 | 350 |
|
347 | 351 |
/* |
348 | 352 |
* int mpool_stats |
... | ... |
@@ -82,8 +82,10 @@ int is_whitelist_ok(const struct cl_engine* engine) |
82 | 82 |
void whitelist_done(struct cl_engine* engine) |
83 | 83 |
{ |
84 | 84 |
if(engine && engine->whitelist_matcher) { |
85 |
- regex_list_done(engine->whitelist_matcher); |
|
86 |
-#ifndef USE_MPOOL |
|
85 |
+ regex_list_done(engine->whitelist_matcher); |
|
86 |
+#ifdef USE_MPOOL |
|
87 |
+ mpool_free(engine->mempool, engine->whitelist_matcher); |
|
88 |
+#else |
|
87 | 89 |
free(engine->whitelist_matcher); |
88 | 90 |
#endif |
89 | 91 |
engine->whitelist_matcher = NULL; |
... | ... |
@@ -907,7 +907,9 @@ void phishing_done(struct cl_engine* engine) |
907 | 907 |
domainlist_done(engine); |
908 | 908 |
if(pchk) { |
909 | 909 |
cli_dbgmsg("Freeing phishcheck struct\n"); |
910 |
-#ifndef USE_MPOOL |
|
910 |
+#ifdef USE_MPOOL |
|
911 |
+ mpool_free(engine->mempool, pchk); |
|
912 |
+#else |
|
911 | 913 |
free(pchk); |
912 | 914 |
#endif |
913 | 915 |
} |
... | ... |
@@ -867,7 +867,11 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb) |
867 | 867 |
switch(apt->type) { |
868 | 868 |
case CLI_TDB_UINT: |
869 | 869 |
off[i] = cnt = tdb->cnt[CLI_TDB_UINT]++; |
870 |
+#ifdef USE_MPOOL |
|
871 |
+ tdb->val = (uint32_t *) mpool_resize2(tdb->mempool, tdb->val, tdb->cnt[CLI_TDB_UINT] * sizeof(uint32_t), NULL); |
|
872 |
+#else |
|
870 | 873 |
tdb->val = (uint32_t *) cli_realloc2(tdb->val, tdb->cnt[CLI_TDB_UINT] * sizeof(uint32_t)); |
874 |
+#endif |
|
871 | 875 |
if(!tdb->val) { |
872 | 876 |
tdb->cnt[CLI_TDB_UINT] = 0; |
873 | 877 |
return -1; |
... | ... |
@@ -883,7 +887,11 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb) |
883 | 883 |
*pt2++ = 0; |
884 | 884 |
off[i] = cnt = tdb->cnt[CLI_TDB_RANGE]; |
885 | 885 |
tdb->cnt[CLI_TDB_RANGE] += 2; |
886 |
+#ifdef USE_MPOOL |
|
887 |
+ tdb->range = (uint32_t *) mpool_resize2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t), NULL); |
|
888 |
+#else |
|
886 | 889 |
tdb->range = (uint32_t *) cli_realloc2(tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t)); |
890 |
+#endif |
|
887 | 891 |
if(!tdb->range) { |
888 | 892 |
tdb->cnt[CLI_TDB_RANGE] = 0; |
889 | 893 |
return -1; |
... | ... |
@@ -899,7 +907,11 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb) |
899 | 899 |
} |
900 | 900 |
off[i] = cnt = tdb->cnt[CLI_TDB_RANGE]; |
901 | 901 |
tdb->cnt[CLI_TDB_RANGE] += 3; |
902 |
+#ifdef USE_MPOOL |
|
903 |
+ tdb->range = (uint32_t *) mpool_resize2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t), NULL); |
|
904 |
+#else |
|
902 | 905 |
tdb->range = (uint32_t *) cli_realloc2(tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t)); |
906 |
+#endif |
|
903 | 907 |
if(!tdb->range) { |
904 | 908 |
tdb->cnt[CLI_TDB_RANGE] = 0; |
905 | 909 |
return -1; |
... | ... |
@@ -916,7 +928,11 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb) |
916 | 916 |
case CLI_TDB_STR: |
917 | 917 |
off[i] = cnt = tdb->cnt[CLI_TDB_STR]; |
918 | 918 |
tdb->cnt[CLI_TDB_STR] += strlen(pt) + 1; |
919 |
+#ifdef USE_MPOOL |
|
920 |
+ tdb->str = (char *) mpool_resize2(tdb->mempool, tdb->str, tdb->cnt[CLI_TDB_STR] * sizeof(char), NULL); |
|
921 |
+#else |
|
919 | 922 |
tdb->str = (char *) cli_realloc2(tdb->str, tdb->cnt[CLI_TDB_STR] * sizeof(char)); |
923 |
+#endif |
|
920 | 924 |
if(!tdb->str) { |
921 | 925 |
cli_errmsg("lsigattribs: Can't allocate memory for tdb->str\n"); |
922 | 926 |
return -1; |
... | ... |
@@ -958,6 +974,16 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb) |
958 | 958 |
return 0; |
959 | 959 |
} |
960 | 960 |
|
961 |
+#ifdef USE_MPOOL |
|
962 |
+#define FREE_TDB(x) do { \ |
|
963 |
+ if(x.cnt[CLI_TDB_UINT]) \ |
|
964 |
+ mpool_free(x.mempool, x.val); \ |
|
965 |
+ if(x.cnt[CLI_TDB_RANGE]) \ |
|
966 |
+ mpool_free(x.mempool, x.range); \ |
|
967 |
+ if(x.cnt[CLI_TDB_STR]) \ |
|
968 |
+ mpool_free(x.mempool, x.str); \ |
|
969 |
+ } while(0); |
|
970 |
+#else |
|
961 | 971 |
#define FREE_TDB(x) \ |
962 | 972 |
if(x.cnt[CLI_TDB_UINT]) \ |
963 | 973 |
free(x.val); \ |
... | ... |
@@ -965,6 +991,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb) |
965 | 965 |
free(x.range); \ |
966 | 966 |
if(x.cnt[CLI_TDB_STR]) \ |
967 | 967 |
free(x.str); |
968 |
+#endif |
|
968 | 969 |
|
969 | 970 |
#define LDB_TOKENS 67 |
970 | 971 |
static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo, unsigned int options, struct cli_dbio *dbio, const char *dbname) |
... | ... |
@@ -1030,6 +1057,7 @@ static int cli_loadldb(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
1030 | 1030 |
|
1031 | 1031 |
/* TDB */ |
1032 | 1032 |
memset(&tdb, 0, sizeof(tdb)); |
1033 |
+ tdb.mempool = (*engine)->mempool; |
|
1033 | 1034 |
|
1034 | 1035 |
if(lsigattribs(tokens[1], &tdb) == -1) { |
1035 | 1036 |
FREE_TDB(tdb); |
... | ... |
@@ -2458,10 +2486,9 @@ void cl_free(struct cl_engine *engine) |
2458 | 2458 |
#ifdef CL_THREAD_SAFE |
2459 | 2459 |
pthread_mutex_unlock(&cli_ref_mutex); |
2460 | 2460 |
#endif |
2461 |
- |
|
2462 | 2461 |
#ifdef USE_MPOOL |
2463 |
- if(engine->mempool) mpool_close(engine->mempool); |
|
2464 |
-#else |
|
2462 |
+#define free(X) mpool_free(engine->mempool, X) |
|
2463 |
+#endif |
|
2465 | 2464 |
if(engine->root) { |
2466 | 2465 |
for(i = 0; i < CLI_MTARGETS; i++) { |
2467 | 2466 |
if((root = engine->root[i])) { |
... | ... |
@@ -2523,15 +2550,17 @@ void cl_free(struct cl_engine *engine) |
2523 | 2523 |
|
2524 | 2524 |
if(((struct cli_dconf *) engine->dconf)->phishing & PHISHING_CONF_ENGINE) |
2525 | 2525 |
phishing_done(engine); |
2526 |
- |
|
2527 | 2526 |
if(engine->dconf) |
2528 | 2527 |
free(engine->dconf); |
2529 | 2528 |
|
2530 | 2529 |
if(engine->pua_cats) |
2531 | 2530 |
free(engine->pua_cats); |
2532 | 2531 |
|
2533 |
- cli_ftfree(engine->ftypes); |
|
2532 |
+ cli_ftfree(engine); |
|
2534 | 2533 |
cli_freeign(engine); |
2534 |
+#ifdef USE_MPOOL |
|
2535 |
+#undef free(X) |
|
2536 |
+ if(engine->mempool) mpool_close(engine->mempool); |
|
2535 | 2537 |
#endif /* USE_MPOOL */ |
2536 | 2538 |
free(engine); |
2537 | 2539 |
} |
... | ... |
@@ -571,9 +571,7 @@ void regex_list_done(struct regex_matcher* matcher) |
571 | 571 |
|
572 | 572 |
if(matcher->list_inited) { |
573 | 573 |
size_t i; |
574 |
-#ifndef USE_MPOOL |
|
575 | 574 |
cli_ac_free(&matcher->suffixes); |
576 |
-#endif |
|
577 | 575 |
if(matcher->suffix_regexes) { |
578 | 576 |
for(i=0;i<matcher->suffix_cnt;i++) { |
579 | 577 |
struct regex_list *r = matcher->suffix_regexes[i].head; |
... | ... |
@@ -591,14 +589,20 @@ void regex_list_done(struct regex_matcher* matcher) |
591 | 591 |
for(i=0;i<matcher->regex_cnt;i++) { |
592 | 592 |
regex_t *r = matcher->all_pregs[i]; |
593 | 593 |
cli_regfree(r); |
594 |
+#ifdef USE_MPOOL |
|
595 |
+ mpool_free(matcher->mempool, r); |
|
596 |
+#else |
|
594 | 597 |
free(r); |
598 |
+#endif |
|
595 | 599 |
} |
600 |
+#ifdef USE_MPOOL |
|
601 |
+ mpool_free(matcher->mempool, matcher->all_pregs); |
|
602 |
+#else |
|
596 | 603 |
free(matcher->all_pregs); |
604 |
+#endif |
|
597 | 605 |
} |
598 | 606 |
hashtab_free(&matcher->suffix_hash); |
599 |
-#ifndef USE_MPOOL |
|
600 | 607 |
cli_bm_free(&matcher->md5_hashes); |
601 |
-#endif |
|
602 | 608 |
} |
603 | 609 |
} |
604 | 610 |
|