From 0d03a730b0ee4b0e8be7e52be70d11e2465d45ae Mon Sep 17 00:00:00 2001 From: Francesco Giudici Date: Wed, 5 Apr 2017 10:48:16 +0200 Subject: nmcli: avoid calling twice "check_activated()" on "nmcli connection up" This happens when the connection is in "activating" state and the connection is a master one waiting for slaves: "check_activated()" is called by the active_connection_state_cb() and device_state_cb() callbacks. If the device has already moved to a state >= NM_DEVICE_STATE_IP_CONFIG, the call to active_connection_state_cb() will end calling activate_connection_info_finish(), freeing the "info" object. The subsequent call to device_state_cb() will result in accessing the freed "info". Just call check_activated() once after registering the active_connection_state() and device_state_cb() callbacks. --- clients/cli/connections.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 72c91df25d..630cefb303 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -2369,17 +2369,16 @@ activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_dat } activate_connection_info_finish (info); } else { - /* Monitor the active connection state state */ - g_signal_connect (G_OBJECT (active), "state-changed", G_CALLBACK (active_connection_state_cb), info); - active_connection_state_cb (active, - nm_active_connection_get_state (active), - nm_active_connection_get_state_reason (active), - info); - - if (device) { + /* Monitor the active connection and device (if available) states */ + g_signal_connect (active, "state-changed", G_CALLBACK (active_connection_state_cb), info); + if (device) g_signal_connect (device, "notify::" NM_DEVICE_STATE, G_CALLBACK (device_state_cb), info); - device_state_cb (device, NULL, info); - } + /* Both active_connection_state_cb () and device_state_cb () will just + * call check_activated (info). So, just call it once directly after + * connecting on both the signals of the objects and skip the call to + * the callbacks. + */ + check_activated (info); /* Start progress indication showing VPN states */ if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) { -- cgit v1.2.1