Browse code

fix error path bug

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@558 77e5149b-7576-45b1-b177-96237e5ba77b

Trog authored on 2004/05/12 23:25:21
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed May 12 15:25:47 BST 2004 (trog)
2
+-----------------------------------
3
+  * libclamav/vba_extract.c: fix error path bug (spotted by Tomasz Klim)
4
+
1 5
 Wed May 12 12:20:50 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/mbox.c:	More bounce false positives removed
... ...
@@ -1005,27 +1005,19 @@ static macro_extnames_t *wm_read_macro_extnames(int fd)
1005 1005
 	offset_end += size;
1006 1006
 	while (lseek(fd, 0, SEEK_CUR) < offset_end) {
1007 1007
 		macro_extnames->count++;
1008
-		if (macro_extnames->count > 0) {
1009
-			macro_extnames->macro_extname = (macro_extname_t *)
1010
-				cli_realloc(macro_extnames->macro_extname,
1011
-					sizeof(macro_extname_t) * macro_extnames->count);
1012
-			if (macro_extnames->macro_extname == NULL) {
1013
-				free(macro_extnames);
1014
-				return NULL;
1015
-			}
1016
-		} else {
1017
-			macro_extnames->macro_extname =
1018
-				(macro_extname_t *) cli_malloc(sizeof(macro_extname_t));
1019
-			if (macro_extnames->macro_extname == NULL) {
1020
-				free(macro_extnames);
1021
-				return NULL;
1022
-			}
1008
+		macro_extnames->macro_extname = (macro_extname_t *)
1009
+			cli_realloc(macro_extnames->macro_extname,
1010
+				sizeof(macro_extname_t) * macro_extnames->count);
1011
+		if (macro_extnames->macro_extname == NULL) {
1012
+			cli_dbgmsg("read macro_extnames failed\n");
1013
+			goto abort;;
1023 1014
 		}
1015
+
1024 1016
 		macro_extname = &macro_extnames->macro_extname[macro_extnames->count-1];
1025 1017
 		if (is_unicode) {
1026 1018
 			if (cli_readn(fd, &macro_extname->length, 1) != 1) {
1027 1019
 				cli_dbgmsg("read macro_extnames failed\n");
1028
-				return NULL;
1020
+				goto abort;
1029 1021
 			}
1030 1022
 			lseek(fd, 1, SEEK_CUR);
1031 1023
 			if (macro_extname->length > 0) {
... ...
@@ -1054,12 +1046,12 @@ static macro_extnames_t *wm_read_macro_extnames(int fd)
1054 1054
 			if (macro_extname->length > 0) {
1055 1055
 			    macro_extname->extname = (char *) cli_malloc(macro_extname->length+1);
1056 1056
 			    if (!macro_extname->extname) {
1057
-				macro_extnames->count--;
1058 1057
 				goto abort;
1059 1058
 			    }
1060 1059
 			    if (cli_readn(fd, macro_extname->extname, macro_extname->length) != 
1061 1060
 						macro_extname->length) {
1062 1061
 				cli_dbgmsg("read macro_extnames failed\n");
1062
+				free(macro_extname->extname);
1063 1063
 				goto abort;
1064 1064
 			    }
1065 1065
 			    macro_extname->extname[macro_extname->length] = '\0';
... ...
@@ -1079,10 +1071,10 @@ static macro_extnames_t *wm_read_macro_extnames(int fd)
1079 1079
 	
1080 1080
 abort:
1081 1081
 	if (macro_extnames->macro_extname != NULL) {
1082
-		for (i=0 ; i < macro_extnames->count ; i++) {
1082
+		for (i=0 ; i < macro_extnames->count-1 ; i++) {
1083 1083
 			free(macro_extnames->macro_extname[i].extname);
1084 1084
 		}
1085
-		free(macro_extname);
1085
+		free(macro_extnames->macro_extname);
1086 1086
 	}
1087 1087
 	free(macro_extnames);
1088 1088
 	return NULL;