1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03: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.

(cherry picked from commit 7e4be6a584)
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-05-09 14:28:36 +02:00
parent 18b3b28e38
commit c1dbf637d7

View File

@ -4680,10 +4680,11 @@ int json_variant_normalize(JsonVariant **v) {
if (!a)
return -ENOMEM;
for (i = 0; i < m; i++) {
for (i = 0; i < m; ) {
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)
goto finish;
}