-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak when exception is thrown in adl_serializer::to_json #3881
Comments
This is throwing inside the constructor. When the constructor doesn't complete without exception, then the destructor is not run, meaning that Off the top of my head, the constructor code that calls out to the adl serializer could detect an exception and call |
…lizer (problem described in issue nlohmann#3881)
This can be solved by either using a base class or a member var to do the cleanup. The stl uses base classes for containers managing memory (https://github.com/gcc-mirror/gcc/blob/7c755fd9018821b79ddc32ee507897860510986c/libstdc%2B%2B-v3/include/bits/stl_vector.h#L423). I will implement a solution using a base class in #3901. /edit |
…lizer (problem described in issue nlohmann#3881)
…lizer (problem described in issue nlohmann#3881)
…lizer (problem described in issue nlohmann#3881)
…lizer (problem described in issue nlohmann#3881)
…lizer (problem described in issue nlohmann#3881)
Description
Throwing an exception in serializer function after the output json object is already initialized results in a memory leak (detected with both ASan and valgrind):
Reproduction steps
Reproducer here: https://godbolt.org/z/dvorMExWh
Expected vs. actual results
Expected: no memory leak
Minimal code example
No response
Error messages
No response
Compiler and operating system
linux, clang 15, gcc 12.2
Library version
3.11.2, godbolt trunk, 7f72eed
Validation
develop
branch is used.The text was updated successfully, but these errors were encountered: