Browse code

libclamav/matcher-bm.c: use mpool in BM's offset mode

Tomasz Kojm authored on 2009/09/19 03:02:42
Showing 4 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Sep 18 20:02:06 CEST 2009 (tk)
2
+----------------------------------
3
+ * libclamav/matcher-bm.c: use mpool in BM's offset mode
4
+
1 5
 Thu Sep 17 22:36:30 CEST 2009 (tk)
2 6
 ----------------------------------
3 7
  * libclamav/matcher-ac.c: implement word delimiter (B) as requested in bb#1631
... ...
@@ -167,15 +167,15 @@ int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, int
167 167
     info.fsize = sb.st_size;
168 168
 
169 169
     data->cnt = data->pos = 0;
170
-    data->offtab = (uint32_t *) cli_malloc(root->bm_patterns * sizeof(uint32_t));
170
+    data->offtab = (uint32_t *) mpool_malloc(root->mempool, root->bm_patterns * sizeof(uint32_t));
171 171
     if(!data->offtab) {
172 172
 	cli_errmsg("cli_bm_initoff: Can't allocate memory for data->offtab\n");
173 173
 	return CL_EMEM;
174 174
     }
175
-    data->offset = (uint32_t *) cli_malloc(root->bm_patterns * sizeof(uint32_t));
175
+    data->offset = (uint32_t *) mpool_malloc(root->mempool, root->bm_patterns * sizeof(uint32_t));
176 176
     if(!data->offset) {
177 177
 	cli_errmsg("cli_bm_initoff: Can't allocate memory for data->offset\n");
178
-	free(data->offtab);
178
+	mpool_free(root->mempool, data->offtab);
179 179
 	return CL_EMEM;
180 180
     }
181 181
     for(i = 0; i < root->bm_patterns; i++) {
... ...
@@ -187,8 +187,8 @@ int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, int
187 187
 	    cli_errmsg("cli_bm_initoff: Can't calculate relative offset in signature for %s\n", patt->virname);
188 188
 	    if(info.exeinfo.section)
189 189
 		free(info.exeinfo.section);
190
-	    free(data->offtab);
191
-	    free(data->offset);
190
+	    mpool_free(root->mempool, data->offtab);
191
+	    mpool_free(root->mempool, data->offset);
192 192
 	    return ret;
193 193
 	} else if((data->offset[patt->offset_min] != CLI_OFF_NONE) && (data->offset[patt->offset_min] + patt->length <= info.fsize)) {
194 194
 	    if(!data->cnt || (data->offset[patt->offset_min] != data->offtab[data->cnt - 1])) {
... ...
@@ -204,11 +204,11 @@ int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, int
204 204
     return CL_SUCCESS;
205 205
 }
206 206
 
207
-void cli_bm_freeoff(struct cli_bm_off *data)
207
+void cli_bm_freeoff(struct cli_bm_off *data, const struct cli_matcher *root)
208 208
 {
209
-    free(data->offset);
209
+    mpool_free(root->mempool, data->offset);
210 210
     data->offset = NULL;
211
-    free(data->offtab);
211
+    mpool_free(root->mempool, data->offtab);
212 212
     data->offtab = NULL;
213 213
 }
214 214
 
... ...
@@ -42,7 +42,7 @@ struct cli_bm_off {
42 42
 int cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern, const char *offset);
43 43
 int cli_bm_init(struct cli_matcher *root);
44 44
 int cli_bm_initoff(const struct cli_matcher *root, struct cli_bm_off *data, int fd);
45
-void cli_bm_freeoff(struct cli_bm_off *data);
45
+void cli_bm_freeoff(struct cli_bm_off *data, const struct cli_matcher *root);
46 46
 int cli_bm_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, const struct cli_matcher *root, uint32_t offset, int fd, struct cli_bm_off *offdata);
47 47
 void cli_bm_free(struct cli_matcher *root);
48 48
 
... ...
@@ -423,7 +423,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
423 423
 		    cli_ac_freedata(&gdata);
424 424
 		cli_ac_freedata(&tdata);
425 425
 		if(bm_offmode)
426
-		    cli_bm_freeoff(&toff);
426
+		    cli_bm_freeoff(&toff, troot);
427 427
 
428 428
 		if(cli_checkfp(desc, ctx))
429 429
 		    return CL_CLEAN;
... ...
@@ -442,7 +442,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
442 442
 		if(troot) {
443 443
 		    cli_ac_freedata(&tdata);
444 444
 		    if(bm_offmode)
445
-			cli_bm_freeoff(&toff);
445
+			cli_bm_freeoff(&toff, troot);
446 446
 		}
447 447
 		if(cli_checkfp(desc, ctx))
448 448
 		    return CL_CLEAN;
... ...
@@ -489,7 +489,7 @@ int cli_scandesc(int desc, cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struc
489 489
 	}
490 490
 	cli_ac_freedata(&tdata);
491 491
 	if(bm_offmode)
492
-	    cli_bm_freeoff(&toff);
492
+	    cli_bm_freeoff(&toff, troot);
493 493
     }
494 494
 
495 495
     if(groot) {