From ea8933136125d07077a97c177580f93cc8c41034 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 28 Jan 2022 23:45:56 +0100 Subject: jplist: Fix a few memory leaks that occur when parsing fails Credit to OSS-Fuzz --- src/jplist.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/jplist.c') 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 @@ static plist_t parse_array(const char* js, jsmntok_t* tokens, int* index) } if (val) { plist_array_append_item(arr, val); + } else { + plist_free(arr); + return NULL; } } *(index) = j; @@ -616,6 +619,7 @@ static plist_t parse_object(const char* js, jsmntok_t* tokens, int* index) 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 @@ static plist_t parse_object(const char* js, jsmntok_t* tokens, int* index) free(key); } else { PLIST_JSON_ERR("%s: keys must be of type STRING\n", __func__); + plist_free(obj); return NULL; } } -- cgit v1.1-32-gdbae