-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Possible memory leak on push_back #1971
Copy link
Copy link
Closed
Labels
kind: bugplatform: visual studiorelated to MSVCrelated to MSVCrelease item: 🐛 bug fixsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
Milestone
Metadata
Metadata
Assignees
Labels
kind: bugplatform: visual studiorelated to MSVCrelated to MSVCrelease item: 🐛 bug fixsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
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.