diff options
author | Thomas Haller <thaller@redhat.com> | 2015-08-11 12:32:27 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-08-13 10:06:42 +0200 |
commit | 13c21baf2eb3f0203da15cc0932e7365aa152a40 (patch) | |
tree | 07b43257c862d6f32f53708e53d0fe7e243cb59a | |
parent | 8bb6ab558efa59c3cf952687a62936aeb7c21439 (diff) | |
download | NetworkManager-13c21baf2eb3f0203da15cc0932e7365aa152a40.tar.gz |
settings: ensure no duplicate plugin instances in load_plugin()
-rw-r--r-- | src/settings/nm-settings.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 211c1b1e70..1ee60ad2c4 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -625,7 +625,7 @@ unrecognized_specs_changed (NMSystemConfigInterface *config, nm_system_config_interface_get_unrecognized_specs); } -static void +static gboolean add_plugin (NMSettings *self, NMSystemConfigInterface *plugin) { NMSettingsPrivate *priv; @@ -633,11 +633,16 @@ add_plugin (NMSettings *self, NMSystemConfigInterface *plugin) char *pinfo = NULL; const char *path; - g_return_if_fail (NM_IS_SETTINGS (self)); - g_return_if_fail (NM_IS_SYSTEM_CONFIG_INTERFACE (plugin)); + g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE); + g_return_val_if_fail (NM_IS_SYSTEM_CONFIG_INTERFACE (plugin), FALSE); priv = NM_SETTINGS_GET_PRIVATE (self); + if (g_slist_find (priv->plugins, plugin)) { + /* don't add duplicates. */ + return FALSE; + } + priv->plugins = g_slist_append (priv->plugins, g_object_ref (plugin)); nm_system_config_interface_init (plugin, NULL); @@ -652,6 +657,8 @@ add_plugin (NMSettings *self, NMSystemConfigInterface *plugin) NM_PRINT_FMT_QUOTED (path, " (", path, ")", "")); g_free (pname); g_free (pinfo); + + return TRUE; } static GObject * @@ -686,7 +693,8 @@ add_keyfile_plugin (NMSettings *self) keyfile_plugin = nm_settings_keyfile_plugin_new (); g_assert (keyfile_plugin); - add_plugin (self, NM_SYSTEM_CONFIG_INTERFACE (keyfile_plugin)); + if (!add_plugin (self, NM_SYSTEM_CONFIG_INTERFACE (keyfile_plugin))) + g_return_if_reached (); } static gboolean @@ -808,8 +816,10 @@ load_plugin: g_object_weak_ref (obj, (GWeakNotify) g_module_close, plugin); g_object_set_data_full (obj, PLUGIN_MODULE_PATH, path, g_free); path = NULL; - add_plugin (self, NM_SYSTEM_CONFIG_INTERFACE (obj)); - list = g_slist_append (list, obj); + if (add_plugin (self, NM_SYSTEM_CONFIG_INTERFACE (obj))) + list = g_slist_append (list, obj); + else + g_object_unref (obj); } next: if (add_ibft && !strcmp (pname, "ifcfg-rh")) { |