3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-10-04 02:18:49 +02:00

netconfig: Allow consecutive calls to _load_settings()

Make consecutive calls to netconfig_load_settings() memory-leak safe by
introducing a netconfig_free_settings convenience method.  This method
will free any settings that are allocated as a result of
netconfig_load_settings() and will be called from netconfig_free() to
ensure that any settings are freed as a result of netconfig_destroy().
This commit is contained in:
Denis Kenzior 2021-09-29 15:54:41 -05:00
parent 3021472358
commit 7f55a241a4

View File

@ -126,6 +126,17 @@ static int sysfs_write_ipv6_setting(const char *ifname, const char *setting,
return r;
}
static void netconfig_free_settings(struct netconfig *netconfig)
{
l_rtnl_address_free(netconfig->v4_address);
netconfig->v4_address = NULL;
l_strfreev(netconfig->dns4_overrides);
netconfig->dns4_overrides = NULL;
l_strfreev(netconfig->dns6_overrides);
netconfig->dns6_overrides = NULL;
}
static void netconfig_free(void *data)
{
struct netconfig *netconfig = data;
@ -1308,12 +1319,7 @@ bool netconfig_load_settings(struct netconfig *netconfig,
}
/* No more validation steps for now, commit new values */
if (v4_address) {
netconfig->v4_address = v4_address;
netconfig->rtm_protocol = RTPROT_STATIC;
} else
netconfig->rtm_protocol = RTPROT_DHCP;
netconfig->rtm_protocol = v4_address ? RTPROT_STATIC : RTPROT_DHCP;
if (!v6_enabled)
netconfig->rtm_v6_protocol = RTPROT_UNSPEC;
@ -1328,6 +1334,11 @@ bool netconfig_load_settings(struct netconfig *netconfig,
resolve_set_mdns(netconfig->resolve, mdns);
l_free(mdns);
netconfig_free_settings(netconfig);
if (netconfig->rtm_protocol == RTPROT_STATIC)
netconfig->v4_address = v4_address;
netconfig->active_settings = active_settings;
netconfig->dns4_overrides = dns4_overrides;
netconfig->dns6_overrides = dns6_overrides;