On Tue, Jun 27, 2006 at 01:30:06PM +0200, [EMAIL PROTECTED] wrote: > Hi, > > the attached patch against CVS saves around 2,5 MB of allocated ac-trie > heap memory with a recent database. It does two things: > > - dont allocate a trans[256] array for last nodes, since those transitions > are never used. > > - dont use the cli_ac_node->islast flag in each node, since it is redundant > to the > cli_ac_node->list pointer, instead check for a set cli_ac_node->list > pointer > to find out about a last node
Hi, the proposed patch caused a segfault on program termination. Please use instead the attached patch for testing. Sorry for the inconvenience ... Best Regards Peter -- Peter Vollmer Software Engineer Innominate Security Technologies AG /device attached security/ tel: +49.30.6392-3687 fax: +49.30.6392-3307 Albert-Einstein-Str. 14 D-12489 Berlin, Germany www.innominate.com
? -p0 ? patch_ac_lastnodes Index: libclamav/clamav.h =================================================================== RCS file: /cvsroot/clamav/clamav-devel/libclamav/clamav.h,v retrieving revision 1.62 diff -b -w -u -r1.62 clamav.h --- libclamav/clamav.h 26 Jun 2006 18:26:32 -0000 1.62 +++ libclamav/clamav.h 30 Jun 2006 13:52:48 -0000 @@ -121,9 +121,9 @@ }; struct cli_ac_node { - char islast; struct cli_ac_patt *list; - struct cli_ac_node *trans[256], *fail; + struct cli_ac_node **trans; + struct cli_ac_node*fail; }; struct cli_md5_node { Index: libclamav/matcher-ac.c =================================================================== RCS file: /cvsroot/clamav/clamav-devel/libclamav/matcher-ac.c,v retrieving revision 1.20 diff -b -w -u -r1.20 matcher-ac.c --- libclamav/matcher-ac.c 26 Jun 2006 18:26:32 -0000 1.20 +++ libclamav/matcher-ac.c 30 Jun 2006 13:52:48 -0000 @@ -64,7 +64,13 @@ cli_dbgmsg("Unable to allocate pattern node (%d)\n", sizeof(struct cli_matcher)); return CL_EMEM; } - + if (i < ac_depth-1) { + next->trans = (struct cli_ac_node **) cli_calloc(256, sizeof(struct cli_ac_node*)); + if(!next->trans) { + cli_dbgmsg("Unable to allocate pattern node trans array\n"); + return CL_EMEM; + } + } root->ac_nodes++; root->ac_nodetable = (struct cli_ac_node **) cli_realloc(root->ac_nodetable, (root->ac_nodes) * sizeof(struct cli_ac_node *)); if(root->ac_nodetable == NULL) { @@ -79,9 +85,8 @@ pos = next; } - pos->islast = 1; - pattern->next = pos->list; + /* list pointer !=NULL also defines a last node */ pos->list = pattern; return CL_SUCCESS; @@ -142,7 +147,8 @@ } while((node = cli_dequeue(&bfs))) { - if(node->islast) + /* last node ? */ + if(node->list) continue; for(i = 0; i < 256; i++) { @@ -216,15 +222,19 @@ for(i = 0; i < root->ac_nodes; i++) { cli_freepatt(root->ac_nodetable[i]->list); + if (root->ac_nodetable[i]->trans) + free(root->ac_nodetable[i]->trans); free(root->ac_nodetable[i]); } if(root->ac_nodetable) free(root->ac_nodetable); - if(root->ac_root) + if(root->ac_root) { + free(root->ac_root->trans); free(root->ac_root); } +} inline static int cli_findpos(const char *buffer, unsigned int depth, unsigned int offset, unsigned int length, const struct cli_ac_patt *pattern) { @@ -313,8 +323,8 @@ for(i = 0; i < length; i++) { current = current->trans[(unsigned char) buffer[i] & 0xff]; - - if(current->islast) { + /* last node ? */ + if(current->list) { position = i - ac_depth + 1; pt = current->list; Index: libclamav/readdb.c =================================================================== RCS file: /cvsroot/clamav/clamav-devel/libclamav/readdb.c,v retrieving revision 1.78 diff -b -w -u -r1.78 readdb.c --- libclamav/readdb.c 26 Jun 2006 18:26:32 -0000 1.78 +++ libclamav/readdb.c 30 Jun 2006 13:52:48 -0000 @@ -513,7 +513,11 @@ cli_errmsg("Can't initialise AC pattern matcher\n"); return CL_EMEM; } - + root->ac_root->trans = (struct cli_ac_node **) cli_calloc(256, sizeof(struct cli_ac_node*)); + if(!root->ac_root->trans) { + cli_errmsg("Can't initialise AC trans array\n"); + return CL_EMEM; + } if(!root->ac_only) { cli_dbgmsg("Initializing BM tables of root[%d]\n", i); if((ret = cli_bm_init(root))) {
_______________________________________________ http://lurker.clamav.net/list/clamav-devel.html