[PATCH 1/2] Revert "shared/compat: fix memory handling of nm_setting_vpn_get_*_keys"



This reverts commit 8ac8c01162235c2c198bfaf25fb7d1a57a595ce5.

The fix was bad because the keys do not come from NMSettingVpn's hash
table but are copies that are freed by nm_setting_vpn_foreach_* before
it returns.
---
 shared/nm-utils/nm-compat.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/shared/nm-utils/nm-compat.c b/shared/nm-utils/nm-compat.c
index 47035e62a16d8a45..22ab675de8373639 100644
--- a/shared/nm-utils/nm-compat.c
+++ b/shared/nm-utils/nm-compat.c
@@ -30,31 +30,39 @@ _get_keys_cb (const char *key, const char *val, gpointer user_data)
 {
        GPtrArray *a = user_data;
 
-       g_ptr_array_add (a, (gpointer) key);
+       g_ptr_array_add (a, g_strdup (key));
 }
 
 static const char **
 _get_keys (NMSettingVpn *setting,
            gboolean is_secrets,
            guint *out_length)
 {
        guint len;
        const char **keys = NULL;
        gs_unref_ptrarray GPtrArray *a = NULL;
 
        nm_assert (NM_IS_SETTING_VPN (setting));
 
        a = g_ptr_array_new ();
        if (is_secrets)
                nm_setting_vpn_foreach_secret (setting, _get_keys_cb, a);
        else
                nm_setting_vpn_foreach_data_item (setting, _get_keys_cb, a);
        len = a->len;
 
        if (a->len) {
                g_ptr_array_sort (a, nm_strcmp_p);
                g_ptr_array_add (a, NULL);
                keys = (const char **) g_ptr_array_free (g_steal_pointer (&a), FALSE);
+
+               /* we need to cache the keys *somewhere*. */
+               g_object_set_qdata_full (G_OBJECT (setting),
+                                        is_secrets
+                                        ? NM_CACHED_QUARK ("libnm._nm_setting_vpn_get_secret_keys")
+                                        : NM_CACHED_QUARK ("libnm._nm_setting_vpn_get_data_keys"),
+                                        keys,
+                                        (GDestroyNotify) g_strfreev);
        }
 
        NM_SET_OUT (out_length, len);
-- 
2.15.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]