summaryrefslogtreecommitdiffstats
path: root/src/jplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2022-01-28 23:45:56 +0100
committerGravatar Nikias Bassen2022-01-28 23:46:25 +0100
commitea8933136125d07077a97c177580f93cc8c41034 (patch)
tree83ec37e452a7d93e157e7fb5020fea7bbd1d0078 /src/jplist.c
parent088cdab964e6cd88b7f15f36eb3e08d38189cd21 (diff)
downloadlibplist-ea8933136125d07077a97c177580f93cc8c41034.tar.gz
libplist-ea8933136125d07077a97c177580f93cc8c41034.tar.bz2
jplist: Fix a few memory leaks that occur when parsing fails
Credit to OSS-Fuzz
Diffstat (limited to 'src/jplist.c')
-rw-r--r--src/jplist.c5
1 files changed, 5 insertions, 0 deletions
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)
596 } 596 }
597 if (val) { 597 if (val) {
598 plist_array_append_item(arr, val); 598 plist_array_append_item(arr, val);
599 } else {
600 plist_free(arr);
601 return NULL;
599 } 602 }
600 } 603 }
601 *(index) = j; 604 *(index) = j;
@@ -616,6 +619,7 @@ static plist_t parse_object(const char* js, jsmntok_t* tokens, int* index)
616 if (tokens[j].type == JSMN_STRING) { 619 if (tokens[j].type == JSMN_STRING) {
617 char* key = unescape_string(js + tokens[j].start, tokens[j].end - tokens[j].start, NULL); 620 char* key = unescape_string(js + tokens[j].start, tokens[j].end - tokens[j].start, NULL);
618 if (!key) { 621 if (!key) {
622 plist_free(obj);
619 return NULL; 623 return NULL;
620 } 624 }
621 plist_t val = NULL; 625 plist_t val = NULL;
@@ -643,6 +647,7 @@ static plist_t parse_object(const char* js, jsmntok_t* tokens, int* index)
643 free(key); 647 free(key);
644 } else { 648 } else {
645 PLIST_JSON_ERR("%s: keys must be of type STRING\n", __func__); 649 PLIST_JSON_ERR("%s: keys must be of type STRING\n", __func__);
650 plist_free(obj);
646 return NULL; 651 return NULL;
647 } 652 }
648 } 653 }