EACH: fix leak when an error is triggered by non-last element of object

Object keys are strings, so they need to be freed.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66070
This commit is contained in:
Emanuele Torre authored and GitHub committed 2024-03-15 14:30:03 +01:00
1 parent c95b34ff82
commit 6f67bae60b
2 files changed
+8 -1

No files matched your search

+3 -1
View File
@@ -781,8 +781,10 @@ jv jq_next(jq_state *jq) {
}
if (!keep_going || raising) {
if (keep_going)
if (keep_going) {
jv_free(key);
jv_free(value);
}
jv_free(container);
goto do_backtrack;
} else if (is_last) {
+5
View File
@@ -178,6 +178,11 @@ map(try .a[] catch ., try .a.[] catch ., .a[]?, .a.[]?)
[{"a": [1,2]}, {"a": 123}]
[1,2,1,2,1,2,1,2,"Cannot iterate over number (123)","Cannot iterate over number (123)"]
# oss-fuzz #66070: objects[] leaks if a non-last element throws an error
try ["OK", (.[] | error)] catch ["KO", .]
{"a":["b"],"c":["d"]}
["KO",["b"]]
#
# Negative array indices
#