Skip to content

Commit

Permalink
Merge pull request #47 from steinwurf/fix-operator-squares-memory-leak
Browse files Browse the repository at this point in the history
Patch: Fixed bug where re-assignment via the operator[] would cause a…
  • Loading branch information
jpihl committed Oct 4, 2023
2 parents ea11363 + 2afbb2e commit 510b562
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ every change, see the Git log.

Latest
------
* tbd
* Patch: Fixed bug where re-assignment via the ``operator[]`` would cause a memory
leak.

10.0.1
------
Expand Down
1 change: 1 addition & 0 deletions src/bourne/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ json& json::operator=(const json& other)
if (this == &other)
return *this;

clear();
switch (other.m_type)
{
case class_type::object:
Expand Down
10 changes: 10 additions & 0 deletions test/src/test_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,13 @@ TEST(test_json, test_unicode_dump)
EXPECT_EQ(expected, object.dump_min());
}
}

TEST(test_json, nested_assignment_cause_memory_leak)
{
bourne::json object1;
bourne::json object2;
object1["key1"] = bourne::json::object();
object2["key2"] = bourne::json::object();
std::cout << "now" << std::endl;
object1["key1"] = object2["key2"];
}

0 comments on commit 510b562

Please sign in to comment.