jplist: Fix a few memory leaks that occur when parsing fails
Credit to OSS-Fuzz
diff --git a/src/jplist.c b/src/jplist.c
index c149d20..88cce28 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -596,6 +596,9 @@
}
if (val) {
plist_array_append_item(arr, val);
+ } else {
+ plist_free(arr);
+ return NULL;
}
}
*(index) = j;
@@ -616,6 +619,7 @@
if (tokens[j].type == JSMN_STRING) {
char* key = unescape_string(js + tokens[j].start, tokens[j].end - tokens[j].start, NULL);
if (!key) {
+ plist_free(obj);
return NULL;
}
plist_t val = NULL;
@@ -643,6 +647,7 @@
free(key);
} else {
PLIST_JSON_ERR("%s: keys must be of type STRING\n", __func__);
+ plist_free(obj);
return NULL;
}
}