Browse code

fix memory leak

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

Tomasz Kojm authored on 2004/07/17 00:41:12
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Jul 16 17:32:40 CEST 2004 (tk)
2
+----------------------------------
3
+  * libclamav: scanners: fix memory leak in new code (thanks to Trog)
4
+
1 5
 Fri Jul 16 02:30:03 CEST 2004 (tk)
2 6
 ----------------------------------
3 7
   * libclamav: fix bug in memory management (thanks to Nigel)
... ...
@@ -357,11 +357,13 @@ int cl_scanbuff(const char *buffer, unsigned int length, const char **virname, c
357 357
 
358 358
     if((partoff = (unsigned long int *) cli_calloc(root->partsigs + 1, sizeof(unsigned long int))) == NULL) {
359 359
 	cli_dbgmsg("cli_scanbuff(): unable to cli_calloc(%d, %d)\n", root->partsigs + 1, sizeof(unsigned long int));
360
+	free(partcnt);
360 361
 	return CL_EMEM;
361 362
     }
362 363
 
363 364
     ret = cli_scanbuff(buffer, length, virname, root, partcnt, 0, 0, partoff);
364 365
 
365 366
     free(partcnt);
367
+    free(partoff);
366 368
     return ret;
367 369
 }
... ...
@@ -127,6 +127,8 @@ static int cli_scandesc(int desc, const char **virname, long int *scanned, const
127 127
 
128 128
     if((partoff = (unsigned long int *) cli_calloc(root->partsigs + 1, sizeof(unsigned long int))) == NULL) {
129 129
 	cli_dbgmsg("cli_scanbuff(): unable to cli_calloc(%d, %d)\n", root->partsigs + 1, sizeof(unsigned long int));
130
+	free(buffer);
131
+	free(partcnt);
130 132
 	return CL_EMEM;
131 133
     }
132 134
 
... ...
@@ -151,6 +153,7 @@ static int cli_scandesc(int desc, const char **virname, long int *scanned, const
151 151
 	if((ret = cli_scanbuff(pt, length, virname, root, partcnt, typerec, offset, partoff)) == CL_VIRUS) {
152 152
 	    free(buffer);
153 153
 	    free(partcnt);
154
+	    free(partoff);
154 155
 	    return ret;
155 156
 
156 157
 	} else if(typerec && ret >= CL_TYPENO) {
... ...
@@ -187,6 +190,7 @@ static int cli_scandesc(int desc, const char **virname, long int *scanned, const
187 187
 
188 188
     free(buffer);
189 189
     free(partcnt);
190
+    free(partoff);
190 191
 
191 192
     md5_finish_ctx(&ctx, &md5buff);
192 193
 
... ...
@@ -777,6 +781,7 @@ static int cli_scanhtml(int desc, const char **virname, long int *scanned, const
777 777
     return CL_CLEAN;
778 778
 #endif
779 779
 
780
+#ifdef HAVE_MMAP
780 781
     /* TODO: do file operations if mmap fails */
781 782
     if(membuff == MAP_FAILED) {
782 783
 	cli_dbgmsg("mmap failed\n");
... ...
@@ -802,6 +807,7 @@ static int cli_scanhtml(int desc, const char **virname, long int *scanned, const
802 802
 
803 803
     free(newbuff);
804 804
     return ret;
805
+#endif
805 806
 }
806 807
 
807 808
 static int cli_scandir(const char *dirname, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, int options, int *arec, int *mrec)