summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-10-06 21:16:00 -0400
committerDan Winship <danw@gnome.org>2014-10-06 21:22:06 -0400
commit330b14839b35c09b1a680bdf5e78620a7d3fad8a (patch)
tree5532dd4207fbd24d1a6ea6e77620930b6a34330d
parentc9e0e66a80429cc6564e47425c86856136d4a329 (diff)
downloadNetworkManager-330b14839b35c09b1a680bdf5e78620a7d3fad8a.tar.gz
libnm: further devices/active_connections NULL-vs-empty fixes
Ensure that NMClient:devices and NMClient:active-connections are always non-NULL (even before initialization completes), and that nm_client_get_devices() and nm_client_get_active_connections() always return non-NULL.
-rw-r--r--libnm/nm-client.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index 053f75ceae..6a4e0b7254 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -145,6 +145,8 @@ nm_client_init (NMClient *client)
priv->state = NM_STATE_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
@@ -423,9 +425,6 @@ nm_client_get_device_by_path (NMClient *client, const char *object_path)
g_return_val_if_fail (object_path, NULL);
devices = nm_client_get_devices (client);
- 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)) {
@@ -457,9 +456,6 @@ nm_client_get_device_by_iface (NMClient *client, const char *iface)
g_return_val_if_fail (iface, NULL);
devices = nm_client_get_devices (client);
- 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)) {
@@ -974,15 +970,9 @@ nm_client_deactivate_connection_finish (NMClient *client,
const GPtrArray *
nm_client_get_active_connections (NMClient *client)
{
- NMClientPrivate *priv;
-
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
- priv = NM_CLIENT_GET_PRIVATE (client);
- if (!nm_client_get_nm_running (client))
- return NULL;
-
- return priv->active_connections;
+ return NM_CLIENT_GET_PRIVATE (client)->active_connections;
}
/**
@@ -1448,7 +1438,10 @@ free_active_connections (NMClient *client, 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];
@@ -1457,10 +1450,8 @@ free_active_connections (NMClient *client, 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 (client), NM_CLIENT_ACTIVE_CONNECTIONS);
- }
}
static void