Uploaded image for project: 'Couchbase C client library libcouchbase'
  1. Couchbase C client library libcouchbase
  2. CCBC-65

Memory leak in libcouchbase_create / libcouchbase_destroy (POC and patch included)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.0.2
    • Fix Version/s: 1.0.4
    • Component/s: library
    • Security Level: Public
    • Labels:
      None
    • Environment:
      Linux Centos

      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.

      1. memory_leak.patch
        1 kB
        James
      2. leak.c
        0.9 kB
        James
      No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

        Hide
        avsej Sergey Avseyev added a comment -

        Good job. Thanks. Your patch imported into review system http://review.couchbase.org/16032

        Show
        avsej Sergey Avseyev added a comment - Good job. Thanks. Your patch imported into review system http://review.couchbase.org/16032
        Hide
        avsej Sergey Avseyev added a comment -

        Merged. Will be accessible in next release or now on the github https://github.com/couchbase/libcouchbase

        Show
        avsej Sergey Avseyev added a comment - Merged. Will be accessible in next release or now on the github https://github.com/couchbase/libcouchbase

          People

          • Assignee:
            avsej Sergey Avseyev
            Reporter:
            jamesoc James
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 4h
              4h
              Remaining:
              Remaining Estimate - 4h
              4h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Gerrit Reviews

                There are no open Gerrit changes