cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: 9K Memory Leak in "content-encoding.c"

From: Song Ma <songmash_at_gmail.com>
Date: Wed, 8 Aug 2007 13:21:09 +0800

Dan,

Your patch is working because that's my first fix to address this problem.
However later on I thought calling "inflateEnd()" and "inflateInit2()" again
are somehow expensive from point of system time&resource consuming. So I
just kept "inflateReset()" since it will reset the z_stream. Somehow I
overlooked the difference of "inflateInit2()" parameters. ("MAX_WBITS+32"
and "-MAX_WBITS"). You are right. Please add exception handling for
"inflateEnd()" calling..
diff -u -r1.24 content_encoding.c
--- content_encoding.c 22 Feb 2007 06:19:39 -0000 1.24
+++ content_encoding.c 8 Aug 2007 04:25:03 -0000
@@ -133,7 +133,7 @@
       /* some servers seem to not generate zlib headers, so this is an
attempt
          to fix and continue anyway */

- inflateReset(z);
+ if (inflateEnd(z) != Z_OK){
+ return process_zlib_error(conn, z);
+ }

       if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
         return process_zlib_error(conn, z);
       }

Best Regards,
Song Ma

2007/8/8, Dan Fandrich <dan_at_coneharvesters.com>:
>
> On Wed, Aug 08, 2007 at 11:25:33AM +0800, Song Ma wrote:
> > I was running the testcase 221 and 223 under valgrind check. I found
> there are
> > 9k memory leak in "content_encoding.c" according to the valgrind's leak
> report.
> > Please refer to the attached files for details.
> >
> > I made one patch for this leak and here is the diff file. I am using the
> latest
> > snapshot: "curl-7.17.0-20070807".
> >
> > Let me know what you think.
>
> The whole point of calling inflateInit2 again is to reinitialize the
> stream
> with different parameters, so commenting out the call defeats the purpose.
> Try this patch instead and let me know if it fixes the problem:
>
> diff -u -r1.24 content_encoding.c
> --- content_encoding.c 22 Feb 2007 06:19:39 -0000 1.24
> +++ content_encoding.c 8 Aug 2007 04:25:03 -0000
> @@ -133,7 +133,7 @@
> /* some servers seem to not generate zlib headers, so this is an
> attempt
> to fix and continue anyway */
>
> - inflateReset(z);
> + inflateEnd(z);
> if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
> return process_zlib_error(conn, z);
> }
>
> >>> Dan
> --
> http://www.MoveAnnouncer.com The web change of address
> service
> Let webmasters know that your web site has moved
>
Received on 2007-08-08