mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 20:50:11 +01:00
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:5c716c8af8Fixes:a2cdf63204
This commit is contained in:
parent
82ef497cc9
commit
3215508293
1 changed files with 11 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue