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: 0a22f4e490 ('libnm: refactor tracking of NMSetting in NMConnection')
(cherry picked from commit 3e3b629586)
This commit is contained in:
Thomas Haller 2022-11-16 19:10:56 +01:00
parent 3e9b5217f3
commit ef29015d0b
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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;