Blob Blame History Raw
--- clamav-0.88.7/libclamav/matcher-ac.c.bz-515	2006-06-29 13:11:31.000000000 +0200
+++ clamav-0.88.7/libclamav/matcher-ac.c	2007-05-31 20:49:21.000000000 +0200
@@ -46,7 +46,7 @@
 
 int cli_ac_addpatt(struct cl_node *root, struct cli_ac_patt *pattern)
 {
-	struct cli_ac_node *pos, *next;
+	struct cli_ac_node *pos, *next, **newtable;
 	int i;
 
     if(pattern->length < AC_MIN_LENGTH)
@@ -65,12 +65,15 @@
 	    }
 
 	    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) {
-		cli_dbgmsg("Unable to realloc nodetable (%d)\n", (root->ac_nodes) * sizeof(struct cl_node *));
+	    newtable = (struct cli_ac_node **) cli_realloc(root->ac_nodetable, (root->ac_nodes) * sizeof(struct cli_ac_node *));
+	    if(!newtable) {
+		root->ac_nodes--;
+		cli_errmsg("cli_ac_addpatt(): Unable to realloc root->ac_nodetable (%u bytes)\n", (root->ac_nodes) * sizeof(struct cli_matcher *));
+		free(next);
 		return CL_EMEM;
 	    }
-	    root->ac_nodetable[root->ac_nodes - 1] = next;
+	    newtable[root->ac_nodes - 1] = next;
+	    root->ac_nodetable = newtable;
 
 	    pos->trans[((unsigned char) pattern->pattern[i]) & 0xff] = next;
 	}