summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2026-02-13 01:05:53 +0100
committerGravatar Nikias Bassen2026-02-13 01:05:53 +0100
commitd5a582e95a0535ba2ec916cf0532dfe29bcd7e6e (patch)
tree6168cefb432fd50f490972e93f0f85f7b0b8b2f5 /src
parent70fd355f94f41bd53d236c9365ed4f888a8818eb (diff)
downloadlibplist-d5a582e95a0535ba2ec916cf0532dfe29bcd7e6e.tar.gz
libplist-d5a582e95a0535ba2ec916cf0532dfe29bcd7e6e.tar.bz2
json: Fix a few memory leaksHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/jplist.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/jplist.c b/src/jplist.c
index 996a3a3..0ac1e0b 100644
--- a/src/jplist.c
+++ b/src/jplist.c
@@ -738,6 +738,11 @@ static plist_t parse_array(const char* js, jsmntok_info_t* ti, int* index, uint3
return NULL;
}
plist_t arr = plist_new_array();
+ if (!arr) {
+ PLIST_JSON_ERR("%s: failed to create array node\n", __func__);
+ ti->err = PLIST_ERR_NO_MEM;
+ return NULL;
+ }
size_t num_tokens = ti->tokens[*index].size;
size_t num;
int j = (*index)+1;
@@ -767,6 +772,13 @@ static plist_t parse_array(const char* js, jsmntok_info_t* ti, int* index, uint3
}
if (val) {
plist_array_append_item(arr, val);
+ // if append failed, val still has no parent, free it and abort
+ if (((node_t)val)->parent == NULL) {
+ plist_free(val);
+ plist_free(arr);
+ ti->err = PLIST_ERR_NO_MEM;
+ return NULL;
+ }
} else {
plist_free(arr);
ti->err = PLIST_ERR_PARSE;
@@ -798,6 +810,11 @@ static plist_t parse_object(const char* js, jsmntok_info_t* ti, int* index, uint
return NULL;
}
plist_t obj = plist_new_dict();
+ if (!obj) {
+ PLIST_JSON_ERR("%s: failed to create dict node\n", __func__);
+ ti->err = PLIST_ERR_NO_MEM;
+ return NULL;
+ }
for (num = 0; num < num_tokens; num++) {
if (j+1 >= ti->count) {
PLIST_JSON_ERR("%s: token index out of valid range\n", __func__);
@@ -833,6 +850,14 @@ static plist_t parse_object(const char* js, jsmntok_info_t* ti, int* index, uint
}
if (val) {
plist_dict_set_item(obj, key, val);
+ // if set failed, val still has no parent, free it and abort
+ if (((node_t)val)->parent == NULL) {
+ plist_free(val);
+ free(key);
+ plist_free(obj);
+ ti->err = PLIST_ERR_NO_MEM;
+ return NULL;
+ }
} else {
free(key);
plist_free(obj);