|
|
594167 |
From 51bbb027e93637f5821215ebb067454ad6620190 Mon Sep 17 00:00:00 2001
|
|
|
594167 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
594167 |
Date: Tue, 10 May 2022 10:51:43 +0200
|
|
|
594167 |
Subject: [PATCH] shared/json: fix memleak in sort
|
|
|
594167 |
|
|
|
594167 |
(cherry picked from commit 99b1145aae682ddd7554c7e3ac5ebf778e88f87d)
|
|
|
594167 |
Related: #2087652
|
|
|
594167 |
---
|
|
|
594167 |
src/shared/json.c | 4 ++--
|
|
|
594167 |
test/fuzz/fuzz-json/leak-sort | 1 +
|
|
|
594167 |
2 files changed, 3 insertions(+), 2 deletions(-)
|
|
|
594167 |
create mode 100644 test/fuzz/fuzz-json/leak-sort
|
|
|
594167 |
|
|
|
594167 |
diff --git a/src/shared/json.c b/src/shared/json.c
|
|
|
594167 |
index 06ef556233..6d23bdf4f9 100644
|
|
|
594167 |
--- a/src/shared/json.c
|
|
|
594167 |
+++ b/src/shared/json.c
|
|
|
594167 |
@@ -4581,7 +4581,7 @@ static int json_cmp_strings(const void *x, const void *y) {
|
|
|
594167 |
|
|
|
594167 |
int json_variant_sort(JsonVariant **v) {
|
|
|
594167 |
_cleanup_free_ JsonVariant **a = NULL;
|
|
|
594167 |
- JsonVariant *n = NULL;
|
|
|
594167 |
+ _cleanup_(json_variant_unrefp) JsonVariant *n = NULL;
|
|
|
594167 |
size_t m;
|
|
|
594167 |
int r;
|
|
|
594167 |
|
|
|
594167 |
@@ -4614,7 +4614,7 @@ int json_variant_sort(JsonVariant **v) {
|
|
|
594167 |
if (!n->sorted) /* Check if this worked. This will fail if there are multiple identical keys used. */
|
|
|
594167 |
return -ENOTUNIQ;
|
|
|
594167 |
|
|
|
594167 |
- JSON_VARIANT_REPLACE(*v, n);
|
|
|
594167 |
+ JSON_VARIANT_REPLACE(*v, TAKE_PTR(n));
|
|
|
594167 |
|
|
|
594167 |
return 1;
|
|
|
594167 |
}
|
|
|
594167 |
diff --git a/test/fuzz/fuzz-json/leak-sort b/test/fuzz/fuzz-json/leak-sort
|
|
|
594167 |
new file mode 100644
|
|
|
594167 |
index 0000000000..f8446dbdc7
|
|
|
594167 |
--- /dev/null
|
|
|
594167 |
+++ b/test/fuzz/fuzz-json/leak-sort
|
|
|
594167 |
@@ -0,0 +1 @@
|
|
|
594167 |
+{"":2,"":6,"-":7}
|
|
|
594167 |
\ No newline at end of file
|