All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Fischer via buildroot <buildroot@buildroot.org>
To: <buildroot@buildroot.org>
Cc: Michael Fischer <mf@go-sys.de>
Subject: [Buildroot] [PATCH] package/json-c: fix memory leak
Date: Mon, 30 Nov 2026 11:01:59 +0100	[thread overview]
Message-ID: <20261130100159.29006-1-mf@go-sys.de> (raw)

json-c 0.19 rewrote json_object_put() iteratively (issue #923). The final
release of every non-empty object/array happens inside an assert():

    assert(_json_object_put_maybe_free(jso, 1) == 0);

Buildroot builds json-c as CMAKE_BUILD_TYPE=Release, i.e. with -DNDEBUG, so
the expression is never evaluated and every non-empty container leaks
(measured on a BlueBox: ~0.5 kB per JSON object, the web interface alone
filled the heap until the memory watchdog restarted the device).

Evaluate the call unconditionally and only assert on its result.

add patch: 0001-json_object_put-do-not-free-inside-assert.patch

Signed-off-by: Michael Fischer <mf@go-sys.de>
---
 ...object_put-do-not-free-inside-assert.patch | 37 +++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 package/json-c/0001-json_object_put-do-not-free-inside-assert.patch

diff --git a/package/json-c/0001-json_object_put-do-not-free-inside-assert.patch b/package/json-c/0001-json_object_put-do-not-free-inside-assert.patch
new file mode 100644
index 0000000000..807d4cf589
--- /dev/null
+++ b/package/json-c/0001-json_object_put-do-not-free-inside-assert.patch
@@ -0,0 +1,37 @@
+From: Michael Fischer <mf@go-sys.de>
+Date: Wed, 11 Nov 2026 15:00:00 +0100
+Subject: [PATCH] json_object_put: do not free containers inside assert()
+
+json-c 0.19 rewrote json_object_put() iteratively (issue #923). The final
+release of every non-empty object/array happens inside an assert():
+
+    assert(_json_object_put_maybe_free(jso, 1) == 0);
+
+Buildroot builds json-c as CMAKE_BUILD_TYPE=Release, i.e. with -DNDEBUG, so
+the expression is never evaluated and every non-empty container leaks
+(measured on a BlueBox: ~0.5 kB per JSON object, the web interface alone
+filled the heap until the memory watchdog restarted the device).
+
+Evaluate the call unconditionally and only assert on its result.
+
+Signed-off-by: Michael Fischer <mf@go-sys.de>
+---
+ json_object.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/json_object.c b/json_object.c
+--- a/json_object.c
++++ b/json_object.c
+@@ -439,7 +439,11 @@ int json_object_put(struct json_object *jso)
+ 			// 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);
++			{
++				int freed = _json_object_put_maybe_free(jso, 1);
++				assert(freed == 0);
++				(void)freed;
++			}
+ 			jso = parent;
+ 			// iteration will be reset at the top of the loop
+ 		}
-- 
2.53.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

             reply	other threads:[~2026-11-30 10:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:01 Michael Fischer via buildroot [this message]
2026-11-30 14:02 ` [Buildroot] [PATCH] package/json-c: fix memory leak Yegor Yefremov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130100159.29006-1-mf@go-sys.de \
    --to=buildroot@buildroot.org \
    --cc=mf@go-sys.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.