You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2011/05/23 20:30:47 UTC

svn commit: r1126638 - /spamassassin/branches/3.2/spamc/libspamc.c

Author: mmartinec
Date: Mon May 23 18:30:46 2011
New Revision: 1126638

URL: http://svn.apache.org/viewvc?rev=1126638&view=rev
Log:
Bug 6025: zlib buffer not freed if compression is used

Modified:
    spamassassin/branches/3.2/spamc/libspamc.c

Modified: spamassassin/branches/3.2/spamc/libspamc.c
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/spamc/libspamc.c?rev=1126638&r1=1126637&r2=1126638&view=diff
==============================================================================
--- spamassassin/branches/3.2/spamc/libspamc.c (original)
+++ spamassassin/branches/3.2/spamc/libspamc.c Mon May 23 18:30:46 2011
@@ -623,6 +623,15 @@ static void _clear_message(struct messag
     m->content_length = -1;
 }
 
+static void _free_zlib_buffer(unsigned char **zlib_buf, int *zlib_bufsiz)
+{
+	if(*zlib_buf) {
+	free(*zlib_buf);
+	*zlib_buf=NULL;
+	}
+	*zlib_bufsiz=0;
+}
+
 static void _use_msg_for_out(struct message *m)
 {
     if (m->outbuf)
@@ -1233,6 +1242,7 @@ int message_filter(struct transport *tp,
     if (zlib_on) {
         if (_zlib_compress(m->msg, m->msg_len, &zlib_buf, &zlib_bufsiz, flags) != EX_OK)
         {
+            _free_zlib_buffer(&zlib_buf, &zlib_bufsiz);
             return EX_OSERR;
         }
         towrite_buf = zlib_buf;
@@ -1243,6 +1253,9 @@ int message_filter(struct transport *tp,
       if (username != NULL) {
 	if (strlen(username) + 8 >= (bufsiz - len)) {
           _use_msg_for_out(m);
+	   if (zlib_on) {
+          _free_zlib_buffer(&zlib_buf, &zlib_bufsiz);
+	   }
           return EX_OSERR;
 	}
 	strcpy(buf + len, "User: ");
@@ -1255,6 +1268,9 @@ int message_filter(struct transport *tp,
       }
       if ((m->msg_len > SPAMC_MAX_MESSAGE_LEN) || ((len + 27) >= (bufsiz - len))) {
 	_use_msg_for_out(m);
+	if (zlib_on) {
+	_free_zlib_buffer(&zlib_buf, &zlib_bufsiz);
+	}
 	return EX_DATAERR;
       }
       len += snprintf(buf + len, 8192-len, "Content-length: %d\r\n\r\n", (int) towrite_len);
@@ -1269,6 +1285,9 @@ int message_filter(struct transport *tp,
 
     if (rc != EX_OK) {
 	_use_msg_for_out(m);
+	if (zlib_on) {
+	_free_zlib_buffer(&zlib_buf, &zlib_bufsiz);
+	}
 	return rc;      /* use the error code try_to_connect_*() gave us. */
     }
 
@@ -1293,6 +1312,13 @@ int message_filter(struct transport *tp,
 	shutdown(sock, SHUT_WR);
     }
 
+    /* free zlib buffer
+    * bug 6025: zlib buffer not freed if compression is used
+    */
+    if (zlib_on) {
+    _free_zlib_buffer(&zlib_buf, &zlib_bufsiz);
+    }
+
     /* ok, now read and parse it.  SPAMD/1.2 line first... */
     failureval =
 	_spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz);