mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 08:10:17 +01:00
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.
This commit is contained in:
parent
88efa1c437
commit
ab878f7479
7 changed files with 28 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 ();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue