From b15a9b3dc4459f228e699a5cf6a3bd4a5ff71ee3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2020 12:27:36 +0100 Subject: [PATCH] supplicant: allocate blobs hash table lazily for supplicant config It's very unlikely that we have actual blobs for a Wi-Fi network. That is because the settings plugins (keyfile, ifcfg-rh) convert blobs to files on disk when writing the profile. So, you can only have them by editing the files directly to contain blobs. At that point, don't always create the GHashTable for blobs. --- src/supplicant/nm-supplicant-config.c | 11 ++++---- src/supplicant/nm-supplicant-interface.c | 35 +++++++++++++----------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/supplicant/nm-supplicant-config.c b/src/supplicant/nm-supplicant-config.c index 2e16f278e1..ec84f9f765 100644 --- a/src/supplicant/nm-supplicant-config.c +++ b/src/supplicant/nm-supplicant-config.c @@ -88,10 +88,6 @@ nm_supplicant_config_init (NMSupplicantConfig * self) g_free, (GDestroyNotify) config_option_free); - priv->blobs = g_hash_table_new_full (nm_str_hash, g_str_equal, - g_free, - (GDestroyNotify) g_bytes_unref); - priv->ap_scan = 1; priv->dispose_has_run = FALSE; } @@ -224,6 +220,11 @@ nm_supplicant_config_add_blob (NMSupplicantConfig *self, nm_log_info (LOGD_SUPPLICANT, "Config: added '%s' value '%s'", key, opt->value); g_hash_table_insert (priv->config, g_strdup (key), opt); + if (!priv->blobs) { + priv->blobs = g_hash_table_new_full (nm_str_hash, g_str_equal, + g_free, + (GDestroyNotify) g_bytes_unref); + } g_hash_table_insert (priv->blobs, g_strdup (blobid), g_bytes_ref (value)); @@ -259,7 +260,7 @@ nm_supplicant_config_finalize (GObject *object) NMSupplicantConfigPrivate *priv = NM_SUPPLICANT_CONFIG_GET_PRIVATE (object); g_hash_table_destroy (priv->config); - g_hash_table_destroy (priv->blobs); + nm_clear_pointer (&priv->blobs, g_hash_table_destroy); G_OBJECT_CLASS (nm_supplicant_config_parent_class)->finalize (object); } diff --git a/src/supplicant/nm-supplicant-interface.c b/src/supplicant/nm-supplicant-interface.c index fca997aa2d..04f35e4182 100644 --- a/src/supplicant/nm-supplicant-interface.c +++ b/src/supplicant/nm-supplicant-interface.c @@ -2154,26 +2154,29 @@ assoc_add_network_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_dat /* Send blobs first; otherwise jump to selecting the network */ blobs = nm_supplicant_config_get_blobs (priv->assoc_data->cfg); - priv->assoc_data->blobs_left = g_hash_table_size (blobs); + priv->assoc_data->blobs_left = blobs + ? g_hash_table_size (blobs) + : 0u; _LOGT ("assoc[%p]: network added (%s) (%u blobs left)", priv->assoc_data, priv->net_path, priv->assoc_data->blobs_left); - if (priv->assoc_data->blobs_left == 0) + if (priv->assoc_data->blobs_left == 0) { assoc_call_select_network (self); - else { - g_hash_table_iter_init (&iter, blobs); - while (g_hash_table_iter_next (&iter, (gpointer) &blob_name, (gpointer) &blob_data)) { - g_dbus_proxy_call (priv->iface_proxy, - "AddBlob", - g_variant_new ("(s@ay)", - blob_name, - nm_utils_gbytes_to_variant_ay (blob_data)), - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->assoc_data->cancellable, - (GAsyncReadyCallback) assoc_add_blob_cb, - self); - } + return; + } + + g_hash_table_iter_init (&iter, blobs); + while (g_hash_table_iter_next (&iter, (gpointer) &blob_name, (gpointer) &blob_data)) { + g_dbus_proxy_call (priv->iface_proxy, + "AddBlob", + g_variant_new ("(s@ay)", + blob_name, + nm_utils_gbytes_to_variant_ay (blob_data)), + G_DBUS_CALL_FLAGS_NONE, + -1, + priv->assoc_data->cancellable, + (GAsyncReadyCallback) assoc_add_blob_cb, + self); } }