summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-08-18 14:28:57 +0200
committerThomas Haller <thaller@redhat.com>2015-08-18 14:44:25 +0200
commit58a2e992943cf53929f7a39cdb29a26a904a2d19 (patch)
tree754f83e20338c56f564f8f07ed253913fe4aa14f
parentd9c44114025048bdc09fa418455dd7ab96bb645b (diff)
downloadNetworkManager-58a2e992943cf53929f7a39cdb29a26a904a2d19.tar.gz
manager: fix memleak in system_hostname_changed_cb()
Also, no need to clone the hostname again. Fixes: c9067d8fedf6f6f2d530fd68bbfca7ce68638d38
-rw-r--r--src/nm-manager.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 4915a89e06..c04a910870 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -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);
}
/*******************************************************************/