Browse code

fix small memory leak (bb#359)

git-svn: trunk@2869

Tomasz Kojm authored on 2007/02/26 06:46:38
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sun Feb 25 20:50:54 CET 2007 (tk)
2
+---------------------------------
3
+  * libclamav/scanners.c: fix small memory leak (bb#359)
4
+
1 5
 Sun Feb 25 17:00:31 CET 2007 (acab)
2 6
 -----------------------------------
3 7
   * libclamav/pe.c: fix leaks on upack return (bb#351)
... ...
@@ -1715,33 +1715,25 @@ static int cli_scanraw(int desc, cli_ctx *ctx, cli_file_t type)
1715 1715
 	return CL_EIO;
1716 1716
     }
1717 1717
 
1718
-    if((ret = cli_scandesc(desc, ctx, ftrec, type, 0, &ftoffset)) == CL_VIRUS) {
1719
-	cli_dbgmsg("%s found in descriptor %d.\n", *ctx->virname, desc);
1720
-	return CL_VIRUS;
1721
-
1722
-    } else if(ret < 0) {
1723
-	return ret;
1718
+    ret = cli_scandesc(desc, ctx, ftrec, type, 0, &ftoffset);
1724 1719
 
1725
-    } else if(ret >= CL_TYPENO) {
1720
+    if(ret >= CL_TYPENO) {
1726 1721
 	lseek(desc, 0, SEEK_SET);
1727 1722
 
1728
-	if((nret = cli_scandesc(desc, ctx, 0, ret, 1, NULL)) == CL_VIRUS) {
1723
+	nret = cli_scandesc(desc, ctx, 0, ret, 1, NULL);
1724
+	if(nret == CL_VIRUS)
1729 1725
 	    cli_dbgmsg("%s found in descriptor %d when scanning file type %u\n", *ctx->virname, desc, ret);
1730
-	    return CL_VIRUS;
1731
-	}
1732 1726
 
1733 1727
 	ret == CL_TYPE_MAIL ? ctx->mrec++ : ctx->arec++;
1734
-	switch(ret) {
1728
+	if(nret != CL_VIRUS) switch(ret) {
1735 1729
 	    case CL_TYPE_HTML:
1736 1730
 		if(SCAN_HTML && type == CL_TYPE_UNKNOWN_TEXT && (DCONF_DOC & DOC_CONF_HTML))
1737
-		    if((nret = cli_scanhtml(desc, ctx)) == CL_VIRUS)
1738
-			return CL_VIRUS;
1731
+		    nret = cli_scanhtml(desc, ctx);
1739 1732
 		break;
1740 1733
 
1741 1734
 	    case CL_TYPE_MAIL:
1742 1735
 		if(SCAN_MAIL && type == CL_TYPE_UNKNOWN_TEXT && (DCONF_MAIL & MAIL_CONF_MBOX))
1743
-		    if((nret = cli_scanmail(desc, ctx)) == CL_VIRUS)
1744
-			return CL_VIRUS;
1736
+		    nret = cli_scanmail(desc, ctx);
1745 1737
 		break;
1746 1738
 
1747 1739
 	    case CL_TYPE_RARSFX:
... ...
@@ -1769,15 +1761,6 @@ static int cli_scanraw(int desc, cli_ctx *ctx, cli_file_t type)
1769 1769
 			    fpt = fpt->next;
1770 1770
 			}
1771 1771
 		    }
1772
-
1773
-		    while(ftoffset) {
1774
-			fpt = ftoffset;
1775
-			ftoffset = ftoffset->next;
1776
-			free(fpt);
1777
-		    }
1778
-
1779
-		    if(nret == CL_VIRUS)
1780
-			return nret;
1781 1772
 		}
1782 1773
 		break;
1783 1774
 
... ...
@@ -1788,6 +1771,15 @@ static int cli_scanraw(int desc, cli_ctx *ctx, cli_file_t type)
1788 1788
 	ret = nret;
1789 1789
     }
1790 1790
 
1791
+    while(ftoffset) {
1792
+	fpt = ftoffset;
1793
+	ftoffset = ftoffset->next;
1794
+	free(fpt);
1795
+    }
1796
+
1797
+    if(ret == CL_VIRUS)
1798
+	cli_dbgmsg("%s found in descriptor %d\n", *ctx->virname, desc);
1799
+
1791 1800
     return ret;
1792 1801
 }
1793 1802