|
@@ -541,8 +541,8 @@ cJSON *cJSON_Duplicate(cJSON *item,int recurse)
|
|
|
if (!newitem) return 0;
|
|
|
/* Copy over all vars */
|
|
|
newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble;
|
|
|
- if (item->valuestring) newitem->valuestring=cJSON_strdup(item->valuestring);
|
|
|
- if (item->string) newitem->string=cJSON_strdup(item->string);
|
|
|
+ if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}}
|
|
|
+ if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}}
|
|
|
/* If non-recursive, then we're done! */
|
|
|
if (!recurse) return newitem;
|
|
|
/* Walk the ->next chain for the child. */
|
|
@@ -550,6 +550,7 @@ cJSON *cJSON_Duplicate(cJSON *item,int recurse)
|
|
|
while (cptr)
|
|
|
{
|
|
|
newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */
|
|
|
+ if (!newchild) {cJSON_Delete(newitem);return 0;}
|
|
|
if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */
|
|
|
else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */
|
|
|
cptr=cptr->next;
|