json-c/backport-Handle-NULL-gracefully-in-json_tokener_free.patch
sun_haii_10 f3a34be86a backport patches
(cherry picked from commit 55884d2a03bcbf977c752a1a383c8064805ee55c)
2025-03-18 15:31:47 +08:00

33 lines
865 B
Diff

From 828c12b22661de53d6497bd1410c68cb153b4f35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Wed, 6 Nov 2024 15:19:04 +0100
Subject: [PATCH] Handle NULL gracefully in json_tokener_free
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Similarly to glibc's free, make json_tokener_free(NULL)
a no-op, to simplify cleanup paths.
Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
json_tokener.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/json_tokener.c b/json_tokener.c
index c831f8a..4453c89 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -182,6 +182,8 @@ struct json_tokener *json_tokener_new(void)
void json_tokener_free(struct json_tokener *tok)
{
+ if (!tok)
+ return;
json_tokener_reset(tok);
if (tok->pb)
printbuf_free(tok->pb);
--
2.35.1.windows.2