1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-06 13:17:44 +03:00

sd-device: fix double-free

If an attribute is read but the value is not used (i.e. ret_value is NULL),
then sd_device_get_sysattr_value() mistakenly frees the read data even though
it is cached internally.

Fixes a bug introduced by acfc2a1d15.

Fixes #25702.

(cherry picked from commit eb18e7b782)
(cherry picked from commit aeb3653744)
This commit is contained in:
Yu Watanabe 2022-12-12 14:16:09 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent f2f863c51f
commit 8f4d5828aa

View File

@ -2166,9 +2166,14 @@ _public_ int sd_device_get_sysattr_value(sd_device *device, const char *sysattr,
sysattr, value, ret_value ? "" : ", ignoring");
if (ret_value)
return r;
} else if (ret_value)
*ret_value = TAKE_PTR(value);
return 0;
}
if (ret_value)
*ret_value = value;
TAKE_PTR(value);
return 0;
}