Fix leak and crash when an allocation throws during parsing (#6023)

json_sax_dom_parser::insert_key_with_index: own the new object_key_index
in a unique_ptr before key_indexes may reallocate; a throwing reallocation
leaked it.

Signed-off-by: Christoph Grüninger <foss@grueninger.de>
This commit is contained in:
Christoph Grüninger authored and GitHub committed 2026-11-04 23:38:47 +01:00
1 parent a49242f088
commit 1da8735154
2 files changed
+4 -2

No files matched your search

+2 -1
View File
@@ -904,7 +904,8 @@ class json_sax_dom_parser : public json_sax_dom_error_state
{
hashes.push_back(hasher(element.first));
}
ordered_data.key_indexes.emplace_back(new object_key_index(std::move(hashes)));
std::unique_ptr<object_key_index> index(new object_key_index(std::move(hashes))); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique): std::make_unique is C++14
ordered_data.key_indexes.push_back(std::move(index));
f.ordered.index = ordered_data.key_indexes.back().get();
}
+2 -1
View File
@@ -16538,7 +16538,8 @@ class json_sax_dom_parser : public json_sax_dom_error_state
{
hashes.push_back(hasher(element.first));
}
ordered_data.key_indexes.emplace_back(new object_key_index(std::move(hashes)));
std::unique_ptr<object_key_index> index(new object_key_index(std::move(hashes))); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique): std::make_unique is C++14
ordered_data.key_indexes.push_back(std::move(index));
f.ordered.index = ordered_data.key_indexes.back().get();
}