Browse code

fix memory leak (bb #1291)

git-svn: trunk@4395

Török Edvin authored on 2008/11/13 19:03:59
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Nov 13 11:05:20 EET 2008 (edwin)
2
+------------------------------------
3
+ * libclamav/htmlnorm.c: fix memory leak (bb #1291)
4
+
1 5
 Thu Nov 13 02:11:41 CET 2008 (acab)
2 6
 -----------------------------------
3 7
  * libclamav: dlinit in cl_init
... ...
@@ -1485,7 +1485,6 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
1485 1485
 					snprintf(filename, 1024, "%s/rfc2397", dirname);
1486 1486
 					tmp_file = cli_gentemp(filename);
1487 1487
 					if(!tmp_file) {
1488
-						free(file_tmp_o1);
1489 1488
 						goto abort;
1490 1489
 					}
1491 1490
 					cli_dbgmsg("RFC2397 data file: %s\n", tmp_file);
... ...
@@ -1493,7 +1492,6 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
1493 1493
 					free(tmp_file);
1494 1494
 					if (file_tmp_o1->fd < 0) {
1495 1495
 						cli_dbgmsg("open failed: %s\n", filename);
1496
-						free(file_tmp_o1);
1497 1496
 						goto abort;
1498 1497
 					}
1499 1498
 					file_tmp_o1->length = 0;
... ...
@@ -1565,6 +1563,7 @@ static int cli_html_normalise(int fd, m_area_t *m_area, const char *dirname, tag
1565 1565
 					html_output_flush(file_tmp_o1);
1566 1566
 					close(file_tmp_o1->fd);
1567 1567
 					free(file_tmp_o1);
1568
+					file_tmp_o1 = NULL;
1568 1569
 				}
1569 1570
 				state = HTML_SKIP_WS;
1570 1571
 				escape = FALSE;
... ...
@@ -1688,6 +1687,11 @@ abort:
1688 1688
 			close(file_buff_text->fd);
1689 1689
 		free(file_buff_text);
1690 1690
 	}
1691
+	if(file_tmp_o1) {
1692
+		html_output_flush(file_tmp_o1);
1693
+		close(file_tmp_o1->fd);
1694
+		free(file_tmp_o1);
1695
+	}
1691 1696
 	return retval;
1692 1697
 }
1693 1698