Fix memory leak in JsonDeserializer when object key is repeated

This commit is contained in:
Benoit Blanchon
2023-05-25 09:21:54 +02:00
parent 48acf963fb
commit da45c4bc4f
2 changed files with 4 additions and 0 deletions

View File

@ -7,6 +7,7 @@
using ArduinoJson::detail::sizeofArray;
using ArduinoJson::detail::sizeofObject;
using ArduinoJson::detail::sizeofString;
TEST_CASE("deserialize JSON object") {
JsonDocument doc(4096);
@ -281,6 +282,7 @@ TEST_CASE("deserialize JSON object") {
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc["a"] == 2);
REQUIRE(doc.memoryUsage() == 3 * sizeofObject(1) + sizeofString(1));
}
SECTION("Repeated key with zero copy mode") { // issue #1697

View File

@ -285,6 +285,8 @@ class JsonDeserializer {
slot->setKey(savedKey);
object.add(slot);
} else {
variantRelease(slot->data(), pool_);
}
// Parse value