Update of /cvsroot/openantivirus/samba-vscan/icap
In directory sc8-pr-cvs1:/tmp/cvs-serv19342/icap
Modified Files:
Tag: VSCAN_0_3
vscan-icap_core.c
Log Message:
close input/output streams to avoid memory leaks
Index: vscan-icap_core.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/icap/vscan-icap_core.c,v
retrieving revision 1.5.2.2
retrieving revision 1.5.2.3
diff -u -d -r1.5.2.2 -r1.5.2.3
--- vscan-icap_core.c 24 Sep 2003 11:02:15 -0000 1.5.2.2
+++ vscan-icap_core.c 3 Jan 2004 14:59:41 -0000 1.5.2.3
@@ -138,6 +138,7 @@
ICAP_HEADER_S,
strlen(hrhs),
strlen(hrhs)+strlen(ehs));
+
fpin = fdopen(sockfd, "r");
if ( fpin == NULL ) {
vscan_syslog("ERROR: can not open stream for reading - %s", strerror(errno));
@@ -146,6 +147,8 @@
fpout = fdopen(sockfd, "w");
if ( fpout == NULL ) {
+ /* close fpin */
+ fclose(fpin);
vscan_syslog("ERROR: can not open stream for writing - %s", strerror(errno));
return -1;
}
@@ -156,19 +159,31 @@
/* send the headers */
if ( fputs(ihs, fpout) == EOF ) {
vscan_syslog("ERROR: could not send data to ICAP server!");
+ /* closeing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
if ( fputs(hrhs, fpout) == EOF ) {
vscan_syslog("ERROR: could not send data to ICAP server!");
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
if ( fputs(ehs, fpout) == EOF ) {
vscan_syslog("ERROR: could not send data to ICAP server!");
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
/* send length information in hex */
if ( fputs(ls, fpout) == EOF ) {
vscan_syslog("ERROR: could not send data to ICAP server!");
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
fflush(fpout);
@@ -177,6 +192,9 @@
input_file = fopen(scan_file, "r");
if ( input_file == NULL ) {
vscan_syslog("ERROR: could not open file '%s', reason: %s", scan_file, strerror(errno));
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
while ( (!feof(input_file)) && (!ferror(input_file)) ) {
@@ -184,25 +202,40 @@
nwritten = fwrite(buf, 1, nread, fpout);
if ( nread != nwritten ) {
vscan_syslog("ERROR: error while sending data");
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
}
if ( ferror(input_file) ) {
vscan_syslog("ERROR: error while reading file '%s'", scan_file);
+ /* closeing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
if ( fclose(input_file) == EOF ) {
vscan_syslog("ERROR: could not close file '%s', reason: %s", scan_file, strerror(errno));
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
/* now send the 'end marker' */
if ( fputs("\r\n0\r\n\r\n", fpout) == EOF ) {
vscan_syslog("ERROR: could not send data to ICAP server!");
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
if ( fflush(fpout) == EOF ) {
vscan_syslog("ERROR: can not flush output stream - %s", strerror(errno));
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
@@ -221,6 +254,9 @@
if ( strncmp("204", str, 3) == 0 ) {
if ( verbose_file_logging )
vscan_syslog("INFO: file %s is clean", scan_file);
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(0);
}
else if ( strncmp("403", str, 3) == 0 ) {
@@ -228,14 +264,23 @@
} else {
if ( verbose_file_logging )
vscan_syslog("ERROR: file %s not found, not readable or an error occured", scan_file);
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return -2;
}
} else {
vscan_syslog("ERROR: could not parse ICAP response line!");
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
} else {
vscan_syslog("ERROR: got no ICAP response line!");
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(-1);
}
@@ -244,10 +289,15 @@
if ( infected ) {
if ( strncmp("X-Infection-Found", str, 17) == 0 ) {
vscan_icap_log_virus(scan_file, strstr(str, "Threat="), client_ip);
+ /* closing streams */
+ fclose(fpin);
+ fclose(fpout);
return(1);
}
}
}
+ fclose(fpin);
+ fclose(fpout);
return(1);
}
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.