sourcemeta / jsontoolkit

A swiss-army knife for expressive JSON programming in modern C++. Covers JSON, JSON Pointer, JSONL, and JSON Schema
https://jsontoolkit.sourcemeta.com/
Other
38 stars 3 forks source link

Investigate ClangTidy warning on RapidJSON document deep-copy #184

Closed jviotti closed 1 year ago

jviotti commented 1 year ago
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/rapidjson/read.h:60:10: error: Potential leak of memory pointed to by 'document.ownAllocator_' [clang-analyzer-cplusplus.NewDeleteLeaks,-warnings-as-errors]
  return document;
         ^
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/read.h:58:3: note: '?' condition is false
  assert(is_array(value));
  ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/assert.h:99:6: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __ASSERT_FILE_NAME, __LINE__, #e) : (void)0)
     ^
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/read.h:60:3: note: Calling 'copy<const rapidjson::GenericValue<rapidjson::UTF8<>> *, std::back_insert_iterator<std::vector<rapidjson::GenericDocument<rapidjson::UTF8<>>>>>'
  sourcemeta::jsontoolkit::copy(cbegin_array(value), cend_array(value),
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/read.h:45:3: note: Calling 'transform<const rapidjson::GenericValue<rapidjson::UTF8<>> *, std::back_insert_iterator<std::vector<rapidjson::GenericDocument<rapidjson::UTF8<>>>>, (lambda at jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/read.h:46:18)>'
  std::transform(begin, end, output,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__algorithm/transform.h:28:5: note: Loop condition is true.  Entering loop body
    for (; __first != __last; ++__first, (void) ++__result)
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__algorithm/transform.h:29:21: note: Calling 'operator()'
        *__result = __op(*__first);
                    ^~~~~~~~~~~~~~
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/read.h:46:48: note: Calling 'from'
                 [](const auto &json) { return from(json); });
                                               ^~~~~~~~~~
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/rapidjson/read.h:58:23: note: Calling default constructor for 'GenericDocument<rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator<>, rapidjson::CrtAllocator>'
  rapidjson::Document document;
                      ^~~~~~~~
/opt/homebrew/include/rapidjson/document.h:2053:14: note: Field 'allocator_' is null
        if (!allocator_)
             ^
/opt/homebrew/include/rapidjson/document.h:2053:9: note: Taking true branch
        if (!allocator_)
        ^
/opt/homebrew/include/rapidjson/document.h:2054:42: note: Memory is allocated
            ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator());
                                         ^
/opt/homebrew/Cellar/rapidjson/1.1.0/include/rapidjson/error/../rapidjson.h:586:26: note: expanded from macro 'RAPIDJSON_NEW'
#define RAPIDJSON_NEW(x) new x
                         ^~~~~
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/rapidjson/read.h:58:23: note: Returning from default constructor for 'GenericDocument<rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator<>, rapidjson::CrtAllocator>'
  rapidjson::Document document;
                      ^~~~~~~~
jsontoolkit/src/json/include/sourcemeta/jsontoolkit/json/rapidjson/read.h:60:10: note: Potential leak of memory pointed to by 'document.ownAllocator_'
  return document;
jviotti commented 1 year ago

Closing given RapidJSON will no longer be in the project