cURL / Mailing Lists / curl-users / Single Mail

curl-users

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

From: Song Ma <songmash_at_gmail.com>
Date: Wed, 8 Aug 2007 11:25:33 +0800

Hi Daniel,

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.

Best Regards,
Song Ma

--- content_encoding.c.orig 2007-08-08 11:11:59.000000000 +0800
+++ content_encoding.c 2007-08-08 11:22:58.000000000 +0800
@@ -134,9 +134,19 @@
          to fix and continue anyway */

       inflateReset(z);
- if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
- return process_zlib_error(conn, z);
- }
+
+ /*Since this is "restart", there is no need to do "inflateInit2"
again.
+ *because: 1. "inflateInit2" has been called before calling
"inflate_stream()"
+ *2."InflateReset" will reset members in structure of "z_stream"
+ *3.call "inflateInit2()" again will make memory leak because
allocate twice but free once.
+ *4.allocation is much more expensive in system time and resource
then just reset&reuse.
+ */
+
+ /*if (inflateInit2(z, -MAX_WBITS) != Z_OK) {
+ *return process_zlib_error(conn, z);
+ *}
+ */
+
       z->next_in = orig_in;
       z->avail_in = nread;
       allow_restart = 0;
Received on 2007-08-08