From bc614783f032deb166d531161f8eec0ac64f5cc4 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 30 Jul 2019 14:09:40 +0200 Subject: [PATCH] cli: take a reference to device in AddAndActivateInfo The device could vanish in between. --- clients/cli/devices.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/clients/cli/devices.c b/clients/cli/devices.c index d36382f85c..f2625eb68f 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -1840,6 +1840,13 @@ typedef struct { gboolean create; } AddAndActivateInfo; +static void +add_and_activate_info_free (AddAndActivateInfo *info) +{ + g_object_unref (info->device); + g_free (info); +} + static void add_and_activate_cb (GObject *client, GAsyncResult *result, @@ -1887,7 +1894,7 @@ add_and_activate_cb (GObject *client, } } - g_free (info); + add_and_activate_info_free (info); } static void @@ -1946,7 +1953,7 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data) nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; g_object_unref (active); quit (); - g_free (info); + add_and_activate_info_free (info); return; } @@ -1973,7 +1980,7 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data) g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc); } } - g_free (info); + add_and_activate_info_free (info); } static NMCResultCode @@ -2020,7 +2027,7 @@ do_device_connect (NmCli *nmc, int argc, char **argv) info = g_malloc0 (sizeof (AddAndActivateInfo)); info->nmc = nmc; - info->device = device; + info->device = g_object_ref (device); info->hotspot = FALSE; nm_client_activate_connection_async (nmc->client, @@ -3524,7 +3531,7 @@ do_device_wifi_connect (NmCli *nmc, int argc, char **argv) info = g_malloc0 (sizeof (AddAndActivateInfo)); info->nmc = nmc; - info->device = device; + info->device = g_object_ref (device); info->hotspot = FALSE; info->create = !existing_con; if (existing_con) { @@ -3894,7 +3901,7 @@ do_device_wifi_hotspot (NmCli *nmc, int argc, char **argv) info = g_malloc0 (sizeof (AddAndActivateInfo)); info->nmc = nmc; - info->device = device; + info->device = g_object_ref (device); info->hotspot = TRUE; info->create = TRUE;