diff --git a/src/shared/json.c b/src/shared/json.c index 06ef5562331..6d23bdf4f9c 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -4581,7 +4581,7 @@ static int json_cmp_strings(const void *x, const void *y) { int json_variant_sort(JsonVariant **v) { _cleanup_free_ JsonVariant **a = NULL; - JsonVariant *n = NULL; + _cleanup_(json_variant_unrefp) JsonVariant *n = NULL; size_t m; int r; @@ -4614,7 +4614,7 @@ int json_variant_sort(JsonVariant **v) { if (!n->sorted) /* Check if this worked. This will fail if there are multiple identical keys used. */ return -ENOTUNIQ; - JSON_VARIANT_REPLACE(*v, n); + JSON_VARIANT_REPLACE(*v, TAKE_PTR(n)); return 1; } diff --git a/test/fuzz/fuzz-json/leak-sort b/test/fuzz/fuzz-json/leak-sort new file mode 100644 index 00000000000..f8446dbdc7f --- /dev/null +++ b/test/fuzz/fuzz-json/leak-sort @@ -0,0 +1 @@ +{"":2,"":6,"-":7} \ No newline at end of file