Uploaded image for project: 'Couchbase Lite'
  1. Couchbase Lite
  2. CBL-3366

fleece::Doc constructor leaks memory

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 3.1.0
    • 3.1.0
    • LiteCore
    • Security Level: Public
    • None
    • LiteCore 88
    • 5

    Description

      Made aware from this valgrind alert:

      ==3163161== 24 bytes in 2 blocks are definitely lost in loss record 7 of 53
      ==3163161== at 0x4A37F66: malloc (vg_replace_malloc.c:307)
      ==3163161== by 0x503DED3: fleece::sharedBuffer::operator new(unsigned long, unsigned long) (FLSlice.cc:120)
      ==3163161== by 0x503DD9E: FLSlice_Copy (FLSlice.cc:173)
      ==3163161== by 0x1F6EB9: fleece::alloc_slice::alloc_slice(fleece::pure_slice) (slice.hh:809)
      ==3163161== by 0x2BCCBD: C4Test::docBodyEquals(C4Document*, fleece::slice) (c4Test.cc:485)
      ==3163161== by 0x24B26F: (anonymous namespace)::____C_A_T_C_H____T_E_S_T_{}{{_}}32::test() (c4DocumentTest.cc:1025)
      ==3163161== by 0x255889: Catch::NWayMethodTestInvoker<(anonymous namespace)::{}{}{_}_C_A_T_C_H____T_E_S_T_{}{{_}}32>::invoke() const (CatchHelper.hh:60)
      ==3163161== by 0x2E1848: Catch::TestCase::invoke() const (catch.hpp:14167) ==3163161== by 0x2DBB6B: Catch::RunContext::invokeActiveTestCase() (catch.hpp:13027)
      ==3163161== by 0x2DB890: Catch::RunContext::runCurrentTest(std::{}cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::{_}_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (catch.hpp:13000) ==3163161== by 0x2DA306: Catch::RunContext::runTest(Catch::TestCase const&) (catch.hpp:12761)
      ==3163161== by 0x2DD4ED: Catch::(anonymous namespace)::TestGroup::execute() (catch.hpp:13354)

      Static analysis shows that the following occurs from creating and destroying a fleece::Doc

      • alloc_slice is given as the first argument of fleece::Doc
      • Immediately, this memory is moved via std::move to FLSliceResult
      • This moved memory is retained in fleece::impl::Doc to +2
      • On destruction, the fleece::impl::Doc releases the memory to +1
      • The original alloc_slice is destroyed to a no-op since it was std::move
      • The FLSliceResult leaks

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            jianmin.zhao Jianmin Zhao
            jimb Jim Borden
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty