mirror of
https://github.com/systemd/systemd
synced 2024-10-15 04:24:19 +00:00
shared/json: fix memory leak on failed normalization
We need to increase the counter immediately after taking the ref, otherwise we may not unref it properly if we fail before incrementing.
This commit is contained in:
parent
bac06497fe
commit
7e4be6a584
|
@ -4655,10 +4655,11 @@ int json_variant_normalize(JsonVariant **v) {
|
||||||
if (!a)
|
if (!a)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
for (i = 0; i < m; i++) {
|
for (i = 0; i < m; ) {
|
||||||
a[i] = json_variant_ref(json_variant_by_index(*v, i));
|
a[i] = json_variant_ref(json_variant_by_index(*v, i));
|
||||||
|
i++;
|
||||||
|
|
||||||
r = json_variant_normalize(a + i);
|
r = json_variant_normalize(&a[i-1]);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
1
test/fuzz/fuzz-json/leak-normalize-fail
Normal file
1
test/fuzz/fuzz-json/leak-normalize-fail
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[7E73]
|
Loading…
Reference in a new issue