Memory leak in libcouchbase 2.2.0 / lcb_make_http_request ?

Hi,
I've been testing libcouchbase, in particular I used lcb_make_http_request() in order to query a view. I noticed my test program started eating memory a lot, so I tried to identify the reason.

I've been able to reproduce this behavior with the couchview example.

I used:

valgrind -v --tool=memcheck --leak-check=full --show-reachable=yes ./a.out -b -h _design/testview/_view/testview?key=%22test%22

Sadly, this currently prevents me from using libcouchbase, as I need to query my view very frequently. Even more sadly, I also have no idea how to fix this error.

Any ideas?

Thanks!

Gideon

Relevant output:

==331== 5 bytes in 1 blocks are definitely lost in loss record 4 of 66
==331== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==331== by 0x52F5D81: strdup (strdup.c:43)
==331== by 0x504833F: add_header (http.c:81)
==331== by 0x50485AF: setup_headers (http.c:334)
==331== by 0x5049450: lcb_make_http_request (http.c:509)
==331== by 0x402428: main (in /home/.../libcouchbase-2.2.0_ubuntu1204_amd64/libcouchbase-2.2.0/example/yajl/a.out)
==331==
==331== 6 bytes in 1 blocks are definitely lost in loss record 5 of 66
==331== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==331== by 0x52F5D81: strdup (strdup.c:43)
==331== by 0x504839D: add_header (http.c:88)
==331== by 0x50484B5: setup_headers (http.c:309)
==331== by 0x5049450: lcb_make_http_request (http.c:509)
==331== by 0x402428: main (in /home/.../libcouchbase-2.2.0_ubuntu1204_amd64/libcouchbase-2.2.0/example/yajl/a.out)
==331==
==331== 7 bytes in 1 blocks are definitely lost in loss record 6 of 66
==331== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==331== by 0x52F5D81: strdup (strdup.c:43)
==331== by 0x504833F: add_header (http.c:81)
==331== by 0x50484CF: setup_headers (http.c:313)
==331== by 0x5049450: lcb_make_http_request (http.c:509)
==331== by 0x402428: main (in /home/.../libcouchbase-2.2.0_ubuntu1204_amd64/libcouchbase-2.2.0/example/yajl/a.out)
==331==
==331== 11 bytes in 1 blocks are definitely lost in loss record 7 of 66
==331== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==331== by 0x52F5D81: strdup (strdup.c:43)
==331== by 0x504833F: add_header (http.c:81)
==331== by 0x504845C: setup_headers (http.c:305)
==331== by 0x5049450: lcb_make_http_request (http.c:509)
==331== by 0x402428: main (in /home/.../libcouchbase-2.2.0_ubuntu1204_amd64/libcouchbase-2.2.0/example/yajl/a.out)
[...]
==717== LEAK SUMMARY:
==717== definitely lost: 272 bytes in 9 blocks
==717== indirectly lost: 285,137 bytes in 62 blocks
==717== possibly lost: 0 bytes in 0 blocks
==717== still reachable: 6,006 bytes in 16 blocks
==717== suppressed: 0 bytes in 0 blocks
==717==
==717== ERROR SUMMARY: 9 errors from 9 contexts (suppressed: 2 from 2)
--717--

1 Answer

« Back to question.

There is a memory leak in version 2.2.0. This has been fixed in version 2.3.0 - in github it's been fixed here:

commit 8fe063767e86c94ffabde61ba784bff39d34a9c4
Author: Mark Nunberg
Date: Fri Jan 31 18:34:32 2014 -0800

http: free hdr->key and hdr->value

Fixes memleak

Change-Id: Ia384389a5ea45e5098102aa3c0e1d26329e635c3
Reviewed-on: http://review.couchbase.org/33107
Reviewed-by: Brett Lawson
Tested-by: Mark Nunberg

Hi,
took me ages until I found time to test it, but yep that fixes my issue!

TY!