summaryrefslogtreecommitdiffstats
path: root/src/jplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/jplist.c')
-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
738 return NULL; 738 return NULL;
739 } 739 }
740 plist_t arr = plist_new_array(); 740 plist_t arr = plist_new_array();
741 if (!arr) {
742 PLIST_JSON_ERR("%s: failed to create array node\n", __func__);
743 ti->err = PLIST_ERR_NO_MEM;
744 return NULL;
745 }
741 size_t num_tokens = ti->tokens[*index].size; 746 size_t num_tokens = ti->tokens[*index].size;
742 size_t num; 747 size_t num;
743 int j = (*index)+1; 748 int j = (*index)+1;
@@ -767,6 +772,13 @@ static plist_t parse_array(const char* js, jsmntok_info_t* ti, int* index, uint3
767 } 772 }
768 if (val) { 773 if (val) {
769 plist_array_append_item(arr, val); 774 plist_array_append_item(arr, val);
775 // if append failed, val still has no parent, free it and abort
776 if (((node_t)val)->parent == NULL) {
777 plist_free(val);
778 plist_free(arr);
779 ti->err = PLIST_ERR_NO_MEM;
780 return NULL;
781 }
770 } else { 782 } else {
771 plist_free(arr); 783 plist_free(arr);
772 ti->err = PLIST_ERR_PARSE; 784 ti->err = PLIST_ERR_PARSE;
@@ -798,6 +810,11 @@ static plist_t parse_object(const char* js, jsmntok_info_t* ti, int* index, uint
798 return NULL; 810 return NULL;
799 } 811 }
800 plist_t obj = plist_new_dict(); 812 plist_t obj = plist_new_dict();
813 if (!obj) {
814 PLIST_JSON_ERR("%s: failed to create dict node\n", __func__);
815 ti->err = PLIST_ERR_NO_MEM;
816 return NULL;
817 }
801 for (num = 0; num < num_tokens; num++) { 818 for (num = 0; num < num_tokens; num++) {
802 if (j+1 >= ti->count) { 819 if (j+1 >= ti->count) {
803 PLIST_JSON_ERR("%s: token index out of valid range\n", __func__); 820 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
833 } 850 }
834 if (val) { 851 if (val) {
835 plist_dict_set_item(obj, key, val); 852 plist_dict_set_item(obj, key, val);
853 // if set failed, val still has no parent, free it and abort
854 if (((node_t)val)->parent == NULL) {
855 plist_free(val);
856 free(key);
857 plist_free(obj);
858 ti->err = PLIST_ERR_NO_MEM;
859 return NULL;
860 }
836 } else { 861 } else {
837 free(key); 862 free(key);
838 plist_free(obj); 863 plist_free(obj);