#1082·cJSON

在 cJSONUtils_ApplyPatches 中出现了使用后释放问题,当一个补丁删除补丁数组时

作者: Fengxiaoxx创建于 2026年9月17日更新于 2026年9月17日

CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches) { const cJSON *current_patch = NULL;

  • cJSON *patches_copy = NULL;
int status = 0;

if (!cJSON_IsArray(patches))

@@ -1046,27 +1047,34 @@ CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * co return 1; }

  • if (patches != NULL)
  • /* iterate over a copy: patches may be part of object, and applying a
  • * patch can delete it */
  • patches_copy = cJSON_Duplicate(patches, true);
  • if (patches_copy == NULL) {
  •    current_patch = patches->child;
  •    return 1;
    

    }

  • current_patch = patches_copy->child; while (current_patch != NULL) { status = apply_patch(object, current_patch, false); if (status != 0)

内容来源: DaveGamble/cJSON