From 4949434dacf093612a96031306568e9965236edd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 11 Jun 2021 19:09:23 +0200 Subject: [PATCH] libnm: take reference to settings in nm_connection_for_each_setting_value() As we iterate over the settings, let's ensure that they stay alive while we call back to the user data. (cherry picked from commit 207b101238f3f4ace9536961b537da51438d4973) --- src/libnm-core-impl/nm-connection.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c index 851c710016..1e4300e6cb 100644 --- a/src/libnm-core-impl/nm-connection.c +++ b/src/libnm-core-impl/nm-connection.c @@ -2589,14 +2589,19 @@ nm_connection_for_each_setting_value(NMConnection * connection, gpointer user_data) { gs_free NMSetting **settings = NULL; - guint i, length = 0; + guint length = 0; + guint i; g_return_if_fail(NM_IS_CONNECTION(connection)); g_return_if_fail(func); settings = nm_connection_get_settings(connection, &length); + for (i = 1; i < length; i++) + g_object_ref(settings[i]); for (i = 0; i < length; i++) nm_setting_enumerate_values(settings[i], func, user_data); + for (i = 1; i < length; i++) + g_object_unref(settings[i]); } /**