-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Possible memory leak on push_back #1971
Comments
@davide9 could you provide minimal reproducible example? |
Here you can find the code with which I have the bug The issue seems related to the fact that there is no |
It is indeed related, thanks for tracking. It's still a bug though. |
I'll provide pull request soon, it seems only one line (that null assignment) needs to be changed. |
By the way, confirmed on gcc 9.3, so it isn't msvc-specific. |
…_back Fixes #1971 (memory leak in basic_json::push_back)
I'm experiencing a memory leak when using push_back to add strings to a json object
Steps to reproduce:
I'm using Visual Studio 2017 on Windows 10, compiling with standard Debug configuration in x64
My latest synch on this branch was on 28/02/2020 at 15:20 CET.
I've (probably) fixed the issue by removing (on the single header file) the line 19426: val.m_type = value_t::null; from the function void push_back(basic_json&& val).
From my debugging, the issue comes from the fact that the m_value.array->push_back(std::move(val)); is invoking the basic_json(const basic_json&) instead of the basic_json(basic_json&&), which creates a copy of the source value that should still be properly delete by the allocator. My fix shouldn't affect the final result since, if the move constructor is invoked in the push_back of 19422, the move constructor will take care of marking the type of the source basic_json as null.
Hope this will be helpful!
Cheers,
Davide.
The text was updated successfully, but these errors were encountered: