Browse code

fix error path memory leaks

git-svn: trunk@2092

Tomasz Kojm authored on 2006/07/17 19:18:40
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Jul 17 12:15:41 CEST 2006 (tk)
2
+----------------------------------
3
+  * libclamav/pe.c: fix error path memory leaks
4
+
1 5
 Mon Jul 17 11:13:18 BST 2006 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter:	Added sanity check for --server when --external isn't
... ...
@@ -935,8 +935,11 @@ int cli_scanpe(int desc, cli_ctx *ctx)
935 935
 		    return CL_EMEM;
936 936
 		}
937 937
 
938
-		if(!(tempfile = cli_gentemp(NULL)))
938
+		if(!(tempfile = cli_gentemp(NULL))) {
939
+		    free(section_hdr);
940
+		    free(src);
939 941
 		    return CL_EMEM;
942
+		}
940 943
 
941 944
 		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
942 945
 		    cli_dbgmsg("FSG: Can't create file %s\n", tempfile);
... ...
@@ -1135,8 +1138,13 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1135 1135
 		oldep = EC32(optional_hdr32.AddressOfEntryPoint) + 161 + 6 + cli_readint32(buff+163);
1136 1136
 		cli_dbgmsg("FSG: found old EP @%x\n", oldep);
1137 1137
 
1138
-		if(!(tempfile = cli_gentemp(NULL)))
1138
+		if(!(tempfile = cli_gentemp(NULL))) {
1139
+		    free(section_hdr);
1140
+		    free(src);
1141
+		    free(dest);
1142
+		    free(sections);
1139 1143
 		    return CL_EMEM;
1144
+		}
1140 1145
 
1141 1146
 		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1142 1147
 		    cli_dbgmsg("FSG: Can't create file %s\n", tempfile);
... ...
@@ -1340,8 +1348,13 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1340 1340
 		oldep = EC32(optional_hdr32.AddressOfEntryPoint) + gp + 6 + cli_readint32(src+gp+2+oldep);
1341 1341
 		cli_dbgmsg("FSG: found old EP @%x\n", oldep);
1342 1342
 
1343
-		if(!(tempfile = cli_gentemp(NULL)))
1343
+		if(!(tempfile = cli_gentemp(NULL))) {
1344
+		    free(section_hdr);
1345
+		    free(src);
1346
+		    free(dest);
1347
+		    free(sections);
1344 1348
 		    return CL_EMEM;
1349
+		}
1345 1350
 
1346 1351
 		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1347 1352
 		    cli_dbgmsg("FSG: Can't create file %s\n", tempfile);
... ...
@@ -1933,8 +1946,11 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1933 1933
 	
1934 1934
 	free(wwp);
1935 1935
 
1936
-	if(!(tempfile = cli_gentemp(NULL)))
1936
+	if(!(tempfile = cli_gentemp(NULL))) {
1937
+	  free(dest);
1938
+	  free(section_hdr);
1937 1939
 	  return CL_EMEM;
1940
+	}
1938 1941
 
1939 1942
 	if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1940 1943
 	  cli_dbgmsg("WWPack: Can't create file %s\n", tempfile);