guix_mirror_bot pushed a commit to branch master
in repository guix.
commit c4a2ab40ef55d65174b6487a863f16a57ce36ed1
Author: arkhan <[email protected]>
AuthorDate: Mon Nov 2 21:41:48 2026 -0500
gnu: json-c: Fix memory leak in json_object_put.
json_object_put in 0.19 only frees container nodes inside an assert, so
the memory is leaked when built with NDEBUG.
* gnu/packages/patches/json-c-free-objects-outside-assert.patch: New file.
* gnu/packages/web.scm (json-c)[source]: Apply it.
Fixes: guix/guix#12152
Signed-off-by: Liliana Marie Prikler <[email protected]>
Merges: guix/guix#12277
---
.../json-c-free-objects-outside-assert.patch | 33 ++++++++++++++++++++++
gnu/packages/web.scm | 3 +-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/gnu/packages/patches/json-c-free-objects-outside-assert.patch
b/gnu/packages/patches/json-c-free-objects-outside-assert.patch
new file mode 100644
index 00000000000..dceff25f33d
--- /dev/null
+++ b/gnu/packages/patches/json-c-free-objects-outside-assert.patch
@@ -0,0 +1,33 @@
+From f291fa81c6f21d925ea771a8cca597f5886309cc Mon Sep 17 00:00:00 2001
+From: Javid Khan <[email protected]>
+Date: Tue, 30 Jun 2026 18:54:06 +0530
+Subject: [PATCH] free objects outside assert() in json_object_put
+
+Upstream-Status: https://github.com/json-c/json-c/pull/936 (merged 2026-07-04)
+
+---
+ json_object.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/json_object.c b/json_object.c
+index 0a619679bd..bbdc888940 100644
+--- a/json_object.c
++++ b/json_object.c
+@@ -435,11 +435,16 @@ int json_object_put(struct json_object *jso)
+ // All slots are cleared, now pop back up to the parent
+ {
+ json_object *parent = jso->_delete_parent;
++ int rc;
+ // jso is a child that's already been detached from its
parent
+ // so we need to actually free it now
+ assert(jso->_ref_count == 0);
+ jso->_ref_count++; // We're the exclusive owner of
jso, non-atomic add is ok.
+- assert(_json_object_put_maybe_free(jso, 1) == 0);
++ // Note: the call must not be inside assert(), or it
gets
++ // compiled out when NDEBUG is defined and the memory
leaks.
++ rc = _json_object_put_maybe_free(jso, 1);
++ assert(rc == 0);
++ (void)rc;
+ jso = parent;
+ // iteration will be reset at the top of the loop
+ }
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index e0b2dc207c4..7b243290c41 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -1619,7 +1619,8 @@ data.")
version ".tar.gz"))
(sha256
(base32
- "1pi69rbcxnda01clpbfa9vzsripw27ji5xrb0pcinc1fj14h5b9p"))))
+ "1pi69rbcxnda01clpbfa9vzsripw27ji5xrb0pcinc1fj14h5b9p"))
+ (patches (search-patches
"json-c-free-objects-outside-assert.patch"))))
(build-system cmake-build-system)
(native-inputs
;; needed for unit test