[CCBC-65] Memory leak in libcouchbase_create / libcouchbase_destroy (POC and patch included) Created: 15/May/12  Updated: 13/Nov/12  Resolved: 15/May/12

Status: Closed
Project: Couchbase C client library libcouchbase
Component/s: library
Affects Version/s: 1.0.2
Fix Version/s: 1.0.4
Security Level: Public

Type: Bug Priority: Critical
Reporter: James Assignee: Sergey Avseyev
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 4h
Time Spent: Not Specified
Original Estimate: 4h
Environment: Linux Centos

Attachments: File leak.c     Text File memory_leak.patch    

 Description   
When the client calls libcouchbase_create and then later calls libcouchbase_destroy, some memory is leaked. For a client with many threads that open and close couchbase sessions, this will lead to memory exhaustion. The leak is caused by the use of strdup() in setup_boostrap_hosts(). These duplicated strings are not free'd in libcouchbase_destroy. The leak can be seen by using valgrind.

I have attached a proof of concept, and a patch with a proposed fix.

I have only tested on 1.0.2, but other versions may be affected.

 Comments   
Comment by Sergey Avseyev [ 15/May/12 ]
Good job. Thanks. Your patch imported into review system http://review.couchbase.org/16032
Comment by Sergey Avseyev [ 15/May/12 ]
Merged. Will be accessible in next release or now on the github https://github.com/couchbase/libcouchbase
Generated at Sat Nov 22 11:00:22 CST 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.