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