From ab878f7479245fbb8c98d17e0f963afc0a163be7 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 6 Oct 2014 21:16:00 -0400 Subject: [PATCH] libnm: further NULL-vs-empty-array fixes In some cases, code may look at the value of an array-valued property during object initialization, before NMObject has set it to its actual initial value. So ensure that we initialize all such properties to an empty array, rather than leaving them NULL. Also fix another bug in NMClient that could result in priv->active_connections being NULL during certain signal emissions, and fix nm_client_get_active_connections() to not return NULL when NM was not running. --- libnm/nm-active-connection.c | 5 ++++- libnm/nm-device-bond.c | 4 ++++ libnm/nm-device-bridge.c | 4 ++++ libnm/nm-device-team.c | 4 ++++ libnm/nm-device-wifi.c | 4 ++++ libnm/nm-manager.c | 17 +++++++---------- libnm/nm-remote-settings.c | 1 + 7 files changed, 28 insertions(+), 11 deletions(-) diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c index ae36bf78ee..a64877be23 100644 --- a/libnm/nm-active-connection.c +++ b/libnm/nm-active-connection.c @@ -362,8 +362,11 @@ nm_active_connection_get_master (NMActiveConnection *connection) } static void -nm_active_connection_init (NMActiveConnection *ap) +nm_active_connection_init (NMActiveConnection *connection) { + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection); + + priv->devices = g_ptr_array_new (); } static void diff --git a/libnm/nm-device-bond.c b/libnm/nm-device-bond.c index b22d8b30fb..9656de631e 100644 --- a/libnm/nm-device-bond.c +++ b/libnm/nm-device-bond.c @@ -173,7 +173,11 @@ get_hw_address (NMDevice *device) static void nm_device_bond_init (NMDeviceBond *device) { + NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (device); + _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BOND); + + priv->slaves = g_ptr_array_new (); } static void diff --git a/libnm/nm-device-bridge.c b/libnm/nm-device-bridge.c index b4ee25b811..63d9040d49 100644 --- a/libnm/nm-device-bridge.c +++ b/libnm/nm-device-bridge.c @@ -173,7 +173,11 @@ get_hw_address (NMDevice *device) static void nm_device_bridge_init (NMDeviceBridge *device) { + NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device); + _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_BRIDGE); + + priv->slaves = g_ptr_array_new (); } static void diff --git a/libnm/nm-device-team.c b/libnm/nm-device-team.c index 06db4cf84a..ce7a82f9cd 100644 --- a/libnm/nm-device-team.c +++ b/libnm/nm-device-team.c @@ -173,7 +173,11 @@ get_setting_type (NMDevice *device) static void nm_device_team_init (NMDeviceTeam *device) { + NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device); + _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_TEAM); + + priv->slaves = g_ptr_array_new (); } static void diff --git a/libnm/nm-device-wifi.c b/libnm/nm-device-wifi.c index 1d0cd39aa7..f804875719 100644 --- a/libnm/nm-device-wifi.c +++ b/libnm/nm-device-wifi.c @@ -565,12 +565,16 @@ get_hw_address (NMDevice *device) static void nm_device_wifi_init (NMDeviceWifi *device) { + NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device); + _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_WIFI); g_signal_connect (device, "notify::" NM_DEVICE_STATE, G_CALLBACK (state_changed_cb), NULL); + + priv->aps = g_ptr_array_new (); } static void diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index 7bfab68a86..24d7080b65 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -127,6 +127,8 @@ nm_manager_init (NMManager *manager) priv->connectivity = NM_CONNECTIVITY_UNKNOWN; priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->devices = g_ptr_array_new (); + priv->active_connections = g_ptr_array_new (); } static void @@ -647,9 +649,6 @@ nm_manager_get_device_by_path (NMManager *manager, const char *object_path) g_return_val_if_fail (object_path, NULL); devices = nm_manager_get_devices (manager); - if (!devices) - return NULL; - for (i = 0; i < devices->len; i++) { NMDevice *candidate = g_ptr_array_index (devices, i); if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), object_path)) { @@ -672,9 +671,6 @@ nm_manager_get_device_by_iface (NMManager *manager, const char *iface) g_return_val_if_fail (iface, NULL); devices = nm_manager_get_devices (manager); - if (!devices) - return NULL; - for (i = 0; i < devices->len; i++) { NMDevice *candidate = g_ptr_array_index (devices, i); if (!strcmp (nm_device_get_iface (candidate), iface)) { @@ -1097,7 +1093,10 @@ free_active_connections (NMManager *manager, gboolean in_dispose) return; active_connections = priv->active_connections; - priv->active_connections = NULL; + if (in_dispose) + priv->active_connections = NULL; + else + priv->active_connections = g_ptr_array_new (); for (i = 0; i < active_connections->len; i++) { active_connection = active_connections->pdata[i]; @@ -1106,10 +1105,8 @@ free_active_connections (NMManager *manager, gboolean in_dispose) } g_ptr_array_unref (active_connections); - if (!in_dispose) { - priv->active_connections = g_ptr_array_new (); + if (!in_dispose) g_object_notify (G_OBJECT (manager), NM_MANAGER_ACTIVE_CONNECTIONS); - } } static void diff --git a/libnm/nm-remote-settings.c b/libnm/nm-remote-settings.c index 2c2dd597e6..e072e9ac1c 100644 --- a/libnm/nm-remote-settings.c +++ b/libnm/nm-remote-settings.c @@ -652,6 +652,7 @@ nm_remote_settings_init (NMRemoteSettings *self) { NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self); + priv->all_connections = g_ptr_array_new (); priv->visible_connections = g_ptr_array_new (); }