dhcp: use cleanup attribute for get_dhclient_leasefile()

This commit is contained in:
Thomas Haller 2018-10-24 16:19:18 +02:00
parent 7d55b1348b
commit b833d68d68

View file

@ -121,8 +121,8 @@ get_dhclient_leasefile (int addr_family,
const char *uuid,
char **out_preferred_path)
{
char *rundir_path;
char *path;
gs_free char *rundir_path = NULL;
gs_free char *path = NULL;
/* First, see if the lease file is in /run */
rundir_path = g_strdup_printf (NMRUNDIR "/dhclient%s-%s-%s.lease",
@ -132,7 +132,7 @@ get_dhclient_leasefile (int addr_family,
if (g_file_test (rundir_path, G_FILE_TEST_EXISTS)) {
NM_SET_OUT (out_preferred_path, g_strdup (rundir_path));
return rundir_path;
return g_steal_pointer (&rundir_path);
}
/* /var/lib/NetworkManager is the preferred leasefile path */
@ -142,18 +142,14 @@ get_dhclient_leasefile (int addr_family,
iface);
if (g_file_test (path, G_FILE_TEST_EXISTS)) {
g_free (rundir_path);
NM_SET_OUT (out_preferred_path, g_strdup (path));
return path;
return g_steal_pointer (&path);
}
if (nm_config_get_configure_and_quit (nm_config_get ()) == NM_CONFIG_CONFIGURE_AND_QUIT_INITRD) {
g_free (path);
path = rundir_path;
} else {
g_free (rundir_path);
}
NM_SET_OUT (out_preferred_path, g_steal_pointer (&path));
if (nm_config_get_configure_and_quit (nm_config_get ()) == NM_CONFIG_CONFIGURE_AND_QUIT_INITRD)
NM_SET_OUT (out_preferred_path, g_steal_pointer (&rundir_path));
else
NM_SET_OUT (out_preferred_path, g_steal_pointer (&path));
/* If the leasefile we're looking for doesn't exist yet in the new location
* (eg, /var/lib/NetworkManager) then look in old locations to maintain
@ -166,17 +162,16 @@ get_dhclient_leasefile (int addr_family,
path = g_strdup_printf (LOCALSTATEDIR "/lib/dhcp/dhclient%s-%s-%s.lease",
_addr_family_to_path_part (addr_family), uuid, iface);
if (g_file_test (path, G_FILE_TEST_EXISTS))
return path;
return g_steal_pointer (&path);
/* Old Red Hat and Fedora location */
g_free (path);
path = g_strdup_printf (LOCALSTATEDIR "/lib/dhclient/dhclient%s-%s-%s.lease",
_addr_family_to_path_part (addr_family), uuid, iface);
if (g_file_test (path, G_FILE_TEST_EXISTS))
return path;
return g_steal_pointer (&path);
/* Fail */
g_free (path);
return NULL;
}