Skip to content

Commit 510b562

Browse files
authored
Merge pull request #47 from steinwurf/fix-operator-squares-memory-leak
Patch: Fixed bug where re-assignment via the operator[] would cause a…
2 parents ea11363 + 2afbb2e commit 510b562

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ every change, see the Git log.
66

77
Latest
88
------
9-
* tbd
9+
* Patch: Fixed bug where re-assignment via the ``operator[]`` would cause a memory
10+
leak.
1011

1112
10.0.1
1213
------

src/bourne/json.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ json& json::operator=(const json& other)
9292
if (this == &other)
9393
return *this;
9494

95+
clear();
9596
switch (other.m_type)
9697
{
9798
case class_type::object:

test/src/test_json.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,13 @@ TEST(test_json, test_unicode_dump)
302302
EXPECT_EQ(expected, object.dump_min());
303303
}
304304
}
305+
306+
TEST(test_json, nested_assignment_cause_memory_leak)
307+
{
308+
bourne::json object1;
309+
bourne::json object2;
310+
object1["key1"] = bourne::json::object();
311+
object2["key2"] = bourne::json::object();
312+
std::cout << "now" << std::endl;
313+
object1["key1"] = object2["key2"];
314+
}

0 commit comments

Comments
 (0)