Commit 58a2e992 authored by Thomas Haller's avatar Thomas Haller

manager: fix memleak in system_hostname_changed_cb()

Also, no need to clone the hostname again.

Fixes: c9067d8f
parent d9c44114
......@@ -1091,18 +1091,26 @@ system_hostname_changed_cb (NMSettings *settings,
char *hostname;
hostname = nm_settings_get_hostname (priv->settings);
/* nm_settings_get_hostname() does not return an empty hostname. */
nm_assert (!hostname || *hostname);
if (!hostname && !priv->hostname)
return;
if (hostname && priv->hostname && !strcmp (hostname, priv->hostname))
if (hostname && priv->hostname && !strcmp (hostname, priv->hostname)) {
g_free (hostname);
return;
}
/* realloc, to free possibly trailing data after NUL. */
if (hostname)
hostname = g_realloc (hostname, strlen (hostname) + 1);
g_free (priv->hostname);
priv->hostname = (hostname && strlen (hostname)) ? g_strdup (hostname) : NULL;
priv->hostname = hostname;
g_object_notify (G_OBJECT (self), NM_MANAGER_HOSTNAME);
nm_dhcp_manager_set_default_hostname (nm_dhcp_manager_get (), priv->hostname);
g_free (hostname);
}
/*******************************************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment