Browse Source

cJSONUtils_ApplyPatches: Fail if removal failed

Max Bruckner 8 years ago
parent
commit
8efb287ae2
1 changed files with 7 additions and 2 deletions
  1. 7 2
      cJSON_Utils.c

+ 7 - 2
cJSON_Utils.c

@@ -456,10 +456,15 @@ static int cJSONUtils_ApplyPatch(cJSON *object, cJSON *patch)
     if ((opcode == 1) || (opcode == 2))
     {
         /* Get rid of old. */
-        cJSON_Delete(cJSONUtils_PatchDetach(object, (unsigned char*)path->valuestring));
+        cJSON *old_item = cJSONUtils_PatchDetach(object, (unsigned char*)path->valuestring);
+        if (old_item == NULL)
+        {
+            return 13;
+        }
+        cJSON_Delete(old_item);
         if (opcode == 1)
         {
-            /* For Remove, this is job done. */
+            /* For Remove, this job is done. */
             return 0;
         }
     }