Skip to content

Commit

Permalink
shared/json: fix memleak in sort
Browse files Browse the repository at this point in the history
(cherry picked from commit 99b1145)
Related: #2087652
  • Loading branch information
keszybz authored and systemd-rhel-bot committed Jun 14, 2022
1 parent 6e0d847 commit 51bbb02
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/shared/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions test/fuzz/fuzz-json/leak-sort
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"":2,"":6,"-":7}

0 comments on commit 51bbb02

Please sign in to comment.