Blob Blame History Raw
From 6e0d847273e6ef6ee1011fb1c8b6689e64a94276 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 10 May 2022 09:05:43 +0200
Subject: [PATCH] shared/json: fix another memleak in normalization

(cherry picked from commit 3b6ce05537cd3544a15073f920347cabd7a39450)
Related: #2087652
---
 src/shared/json.c                         | 4 ++--
 test/fuzz/fuzz-json/leak-normalize-object | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
 create mode 100644 test/fuzz/fuzz-json/leak-normalize-object

diff --git a/src/shared/json.c b/src/shared/json.c
index bb2363fd98..06ef556233 100644
--- a/src/shared/json.c
+++ b/src/shared/json.c
@@ -4621,7 +4621,7 @@ int json_variant_sort(JsonVariant **v) {
 
 int json_variant_normalize(JsonVariant **v) {
         _cleanup_free_ JsonVariant **a = NULL;
-        JsonVariant *n = NULL;
+        _cleanup_(json_variant_unrefp) JsonVariant *n = NULL;
         size_t i, m;
         int r;
 
@@ -4669,7 +4669,7 @@ int json_variant_normalize(JsonVariant **v) {
                 goto finish;
         }
 
-        JSON_VARIANT_REPLACE(*v, n);
+        JSON_VARIANT_REPLACE(*v, TAKE_PTR(n));
 
         r = 1;
 
diff --git a/test/fuzz/fuzz-json/leak-normalize-object b/test/fuzz/fuzz-json/leak-normalize-object
new file mode 100644
index 0000000000..0a8caa426c
--- /dev/null
+++ b/test/fuzz/fuzz-json/leak-normalize-object
@@ -0,0 +1 @@
+[7,7,7,7,{"":7,"":7,"^t":7,"-":7},2777,7,7,7,3]
\ No newline at end of file