From ef29015d0be0c6f058ab6b41bd145eb0e87c0837 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 16 Nov 2022 19:10:56 +0100 Subject: [PATCH] libnm: fix leak with self assignment in nm_connection_add_setting() We must consume the reference, like we would in the other case. Interestingly, I am unable to reproduce a case where valgrind would complain about the leak. But it is there nonetheless. Fixes: 0a22f4e4905c ('libnm: refactor tracking of NMSetting in NMConnection') (cherry picked from commit 3e3b62958665db5694389d477b507a76ee053b3a) --- src/libnm-core-impl/nm-connection.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c index 8778cd18bf..2f5bf35709 100644 --- a/src/libnm-core-impl/nm-connection.c +++ b/src/libnm-core-impl/nm-connection.c @@ -228,8 +228,10 @@ _nm_connection_add_setting(NMConnection *connection, NMSetting *setting) priv = NM_CONNECTION_GET_PRIVATE(connection); s_old = priv->settings[setting_info->meta_type]; - if (s_old == setting) + if (s_old == setting) { + g_object_unref(s_old); return; + } priv->settings[setting_info->meta_type] = setting;