danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
726 stars 164 forks source link

Memory leak in static analysis #544

Closed Sathavahana1901 closed 3 weeks ago

Sathavahana1901 commented 1 month ago

Memory leak in heap_string

issue: a resource leak in jsoncons/detail/heap_string.hpp at line 158. The warning indicates that a memory resource allocated at new_allocator.h:114 was not freed, and the last reference to it was lost at heap_string.hpp:175.

actual behavior : static code analysis(codesonar) tool reporting memory leak

expected behavior : static code analysis(codesonar) tool report should be clean with out any bugs

run jsoncons through codesonar static analysis tool

Include a small, self-contained example if possible

What compiler, architecture, and operating system?

What jsoncons library version?

danielaparker commented 1 month ago

I'm quite sure that codesonar is wrong. The type heap_string is used to hold basic_json string values, and as such is the most used type in the jsoncons library. We perform memory checks for all builds, and detect no leaks. The diagnostic is wrong, there is no lost reference.