1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-08 21:17:47 +03:00

sd-dhcp-lease: fix memleak

Fixes https://github.com/systemd/systemd/pull/22294#issuecomment-1024840811.

(cherry picked from commit 06cf04dff4)
This commit is contained in:
Yu Watanabe 2022-01-31 05:19:09 +09:00 committed by Luca Boccassi
parent 2b04d3b3fc
commit ae95ca27be

View File

@ -1121,6 +1121,18 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
return 0; return 0;
} }
static char **private_options_free(char **options) {
if (!options)
return NULL;
for (unsigned i = 0; i < SD_DHCP_OPTION_PRIVATE_LAST - SD_DHCP_OPTION_PRIVATE_BASE + 1; i++)
free(options[i]);
return mfree(options);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(char**, private_options_free);
int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
_cleanup_(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL; _cleanup_(sd_dhcp_lease_unrefp) sd_dhcp_lease *lease = NULL;
_cleanup_free_ char _cleanup_free_ char
@ -1143,8 +1155,8 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
*vendor_specific_hex = NULL, *vendor_specific_hex = NULL,
*lifetime = NULL, *lifetime = NULL,
*t1 = NULL, *t1 = NULL,
*t2 = NULL, *t2 = NULL;
*options[SD_DHCP_OPTION_PRIVATE_LAST - SD_DHCP_OPTION_PRIVATE_BASE + 1] = {}; _cleanup_(private_options_freep) char **options = NULL;
int r, i; int r, i;
@ -1155,6 +1167,10 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
if (r < 0) if (r < 0)
return r; return r;
options = new0(char*, SD_DHCP_OPTION_PRIVATE_LAST - SD_DHCP_OPTION_PRIVATE_BASE + 1);
if (!options)
return -ENOMEM;
r = parse_env_file(NULL, lease_file, r = parse_env_file(NULL, lease_file,
"ADDRESS", &address, "ADDRESS", &address,
"ROUTER", &router, "ROUTER", &router,