httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpl...@apache.org
Subject svn commit: r422736 - /httpd/httpd/trunk/modules/filters/mod_deflate.c
Date Mon, 17 Jul 2006 15:08:27 GMT
Author: rpluem
Date: Mon Jul 17 08:08:27 2006
New Revision: 422736

URL: http://svn.apache.org/viewvc?rev=422736&view=rev
Log:
* Fix potential memory leaks in deflate_out_filter if bailing out due to an
  error (either in the lower filter chain or during a libz operation). We need
  to call deflateEnd as it is very likely that this filter is never called
  again to ensures that libz's internal structures get cleaned properly.

Modified:
    httpd/httpd/trunk/modules/filters/mod_deflate.c

Modified: httpd/httpd/trunk/modules/filters/mod_deflate.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/filters/mod_deflate.c?rev=422736&r1=422735&r2=422736&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/filters/mod_deflate.c (original)
+++ httpd/httpd/trunk/modules/filters/mod_deflate.c Mon Jul 17 08:08:27 2006
@@ -502,6 +502,14 @@
             /* flush the remaining data from the zlib buffers */
             zRC = flush_zlib_buffer(ctx, c, f->c->bucket_alloc, Z_SYNC_FLUSH);
             if (zRC != Z_OK) {
+                /*
+                 * Things screwed up. It is likely that we never return into
+                 * this filter, so clean libz's internal structures to avoid a
+                 * possible memory leak.
+                 */
+                deflateEnd(&ctx->stream);
+                /* Remove ourselves to ensure that we really NEVER come back */
+                ap_remove_output_filter(f);
                 return APR_EGENERAL;
             }
 
@@ -510,6 +518,14 @@
             APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
             rv = ap_pass_brigade(f->next, ctx->bb);
             if (rv != APR_SUCCESS) {
+                /*
+                 * Things screwed up. It is likely that we never return into
+                 * this filter, so clean libz's internal structures to avoid a
+                 * possible memory leak.
+                 */
+                deflateEnd(&ctx->stream);
+                /* Remove ourselves to ensure that we really NEVER come back */
+                ap_remove_output_filter(f);
                 return rv;
             }
             continue;
@@ -541,14 +557,31 @@
                 /* Send what we have right now to the next filter. */
                 rv = ap_pass_brigade(f->next, ctx->bb);
                 if (rv != APR_SUCCESS) {
+                    /*
+                     * Things screwed up. It is likely that we never return into
+                     * this filter, so clean libz's internal structures to avoid a
+                     * possible memory leak.
+                     */
+                    deflateEnd(&ctx->stream);
+                    /* Remove ourselves to ensure that we really NEVER come back */
+                    ap_remove_output_filter(f);
                     return rv;
                 }
             }
 
             zRC = deflate(&(ctx->stream), Z_NO_FLUSH);
 
-            if (zRC != Z_OK)
+            if (zRC != Z_OK) {
+                /*
+                 * Things screwed up. It is likely that we never return into
+                 * this filter, so clean libz's internal structures to avoid a
+                 * possible memory leak.
+                 */
+                deflateEnd(&ctx->stream);
+                /* Remove ourselves to ensure that we really NEVER come back */
+                ap_remove_output_filter(f);
                 return APR_EGENERAL;
+            }
         }
 
         apr_bucket_delete(e);



Mime
View raw message