mirror of
https://github.com/nlohmann/json.git
synced 2026-11-05 12:19:21 +00:00
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:
1 parent
a49242f088
commit
1da8735154
2 files changed
+4
-2
No files matched your search
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Generated
+2
-1
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user