cjson/backport-Set-free-d-pointers-to-NULL-whenever-they-are-not-re.patch
Zhao Mengmeng de2287f574 Sync patches from 24.03 branch
Sync these patches from 24.03 branch:
- Fix-a-null-pointer-crash-in-cJSON_ReplaceItemViaPoin.patch
- backport-Add-test-for-heap-buffer-overflow.patch
- backport-Fix-heap-buffer-overflow.patch
- backport-fix-add-allocate-check-for-replace_item_in_object-67.patch
- backport-fix-print-int-without-decimal-places-630.patch
- backport-Set-free-d-pointers-to-NULL-whenever-they-are-not-re.patch

Signed-off-by: Zhao Mengmeng <zhaomengmeng@kylinos.cn>
2024-06-18 16:38:13 +08:00

75 lines
2.0 KiB
Diff

From 0489fa665b373d214523e318ee6b75292ea0e411 Mon Sep 17 00:00:00 2001
From: maebex <maximilian.berndt11@web.de>
Date: Sat, 30 Mar 2024 10:42:22 +0100
Subject: [PATCH] Set free'd pointers to NULL whenever they are not reassigned
immediately after
---
cJSON.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/cJSON.c b/cJSON.c
index 7532e84..ab4fb35 100644
--- a/cJSON.c
+++ b/cJSON.c
@@ -263,10 +263,12 @@ CJSON_PUBLIC(void) cJSON_Delete(cJSON *item)
if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL))
{
global_hooks.deallocate(item->valuestring);
+ item->valuestring = NULL;
}
if (!(item->type & cJSON_StringIsConst) && (item->string != NULL))
{
global_hooks.deallocate(item->string);
+ item->string = NULL;
}
global_hooks.deallocate(item);
item = next;
@@ -900,6 +902,7 @@ fail:
if (output != NULL)
{
input_buffer->hooks.deallocate(output);
+ output = NULL;
}
if (input_pointer != NULL)
@@ -1242,6 +1245,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i
/* free the buffer */
hooks->deallocate(buffer->buffer);
+ buffer->buffer = NULL;
}
return printed;
@@ -1250,11 +1254,13 @@ fail:
if (buffer->buffer != NULL)
{
hooks->deallocate(buffer->buffer);
+ buffer->buffer = NULL;
}
if (printed != NULL)
{
hooks->deallocate(printed);
+ printed = NULL;
}
return NULL;
@@ -1295,6 +1301,7 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON
if (!print_value(item, &p))
{
global_hooks.deallocate(p.buffer);
+ p.buffer = NULL;
return NULL;
}
@@ -3138,4 +3145,5 @@ CJSON_PUBLIC(void *) cJSON_malloc(size_t size)
CJSON_PUBLIC(void) cJSON_free(void *object)
{
global_hooks.deallocate(object);
+ object = NULL;
}
--
2.33.0