summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-04-23 19:14:19 +0200
committerThomas Haller <thaller@redhat.com>2017-05-02 18:24:16 +0200
commit3215508293c26e9e8531c2482def598ef1bbbefd (patch)
tree05f39cf899b48f79a48f221d535fa0f23fd2ee7b
parent82ef497cc9e2728e73cb0426efbae85c83bec3fe (diff)
downloadNetworkManager-3215508293c26e9e8531c2482def598ef1bbbefd.tar.gz
policy: fix memleak in lookup_callback() and cancelling
When the operation is cancelled, we must not touch user_data. Note that NM_POLICY_GET_PRIVATE() theoretically doesn't dereference the pointer (does it?) but doing pointer arithmetic on a dangling pointer is a very ugly thing to do. And of course, the memleak. Fixes: 5c716c8af8ddca1d3f7510494754d875b01a8889 Fixes: a2cdf632045d60b26f7aff470dedb56c1f9b938d
-rw-r--r--src/nm-policy.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index f82260f97f..7c74a6b412 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -560,26 +560,24 @@ lookup_callback (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
- NMPolicy *self = (NMPolicy *) user_data;
- NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
- const char *hostname;
- GError *error = NULL;
+ NMPolicy *self;
+ NMPolicyPrivate *priv;
+ gs_free char *hostname = NULL;
+ gs_free_error GError *error = NULL;
hostname = g_resolver_lookup_by_address_finish (G_RESOLVER (source), result, &error);
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- /* Don't touch policy; it may have been freed already */
- g_error_free (error);
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
- }
+
+ self = user_data;
+ priv = NM_POLICY_GET_PRIVATE (self);
+
+ g_clear_object (&priv->lookup_cancellable);
if (hostname)
_set_hostname (self, hostname, "from address lookup");
- else {
+ else
_set_hostname (self, NULL, error->message);
- g_error_free (error);
- }
-
- g_clear_object (&priv->lookup_cancellable);
}
static void