From e5f41b763ac69714e997db8af714e57b01d6e22e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Dec 2017 11:53:07 +0100 Subject: [PATCH] ifcfg-rh: fix path_watch_stop() not to create inotify-helper Commonly, we don't monitor files and hence don't need the inotify-helper instance. We already access and construct the instance lazy, by accessing the singleton getter only when needed. However, path_watch_stop() would always access the singleton, hence always create such an instance. In most cases there is nothing to clean, and no such instance shall be created. (cherry picked from commit 31f2a466390024be6710b259d5ad228ebf5d1557) --- .../ifcfg-rh/nms-ifcfg-rh-connection.c | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c index 4e2b6560d7..889465f70c 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c @@ -96,14 +96,6 @@ G_DEFINE_TYPE (NMIfcfgConnection, nm_ifcfg_connection, NM_TYPE_SETTINGS_CONNECTI /*****************************************************************************/ -static NMInotifyHelper * -_get_inotify_helper (NMIfcfgConnectionPrivate *priv) -{ - if (!priv->inotify_helper) - priv->inotify_helper = g_object_ref (nm_inotify_helper_get ()); - return priv->inotify_helper; -} - static gboolean devtimeout_ready (gpointer user_data) { @@ -225,35 +217,29 @@ static void path_watch_stop (NMIfcfgConnection *self) { NMIfcfgConnectionPrivate *priv = NM_IFCFG_CONNECTION_GET_PRIVATE (self); - NMInotifyHelper *ih; - ih = _get_inotify_helper (priv); - - nm_clear_g_signal_handler (ih, &priv->ih_event_id); + nm_clear_g_signal_handler (priv->inotify_helper, &priv->ih_event_id); if (priv->file_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->file_wd); + nm_inotify_helper_remove_watch (priv->inotify_helper, priv->file_wd); priv->file_wd = -1; } - g_free (priv->keyfile); - priv->keyfile = NULL; + nm_clear_g_free (&priv->keyfile); if (priv->keyfile_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->keyfile_wd); + nm_inotify_helper_remove_watch (priv->inotify_helper, priv->keyfile_wd); priv->keyfile_wd = -1; } - g_free (priv->routefile); - priv->routefile = NULL; + nm_clear_g_free (&priv->routefile); if (priv->routefile_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->routefile_wd); + nm_inotify_helper_remove_watch (priv->inotify_helper, priv->routefile_wd); priv->routefile_wd = -1; } - g_free (priv->route6file); - priv->route6file = NULL; + nm_clear_g_free (&priv->route6file); if (priv->route6file_wd >= 0) { - nm_inotify_helper_remove_watch (ih, priv->route6file_wd); + nm_inotify_helper_remove_watch (priv->inotify_helper, priv->route6file_wd); priv->route6file_wd = -1; } } @@ -280,7 +266,9 @@ filename_changed (GObject *object, if (nm_config_get_monitor_connection_files (nm_config_get ())) { NMInotifyHelper *ih; - ih = _get_inotify_helper (priv); + if (!priv->inotify_helper) + priv->inotify_helper = g_object_ref (nm_inotify_helper_get ()); + ih = priv->inotify_helper; priv->ih_event_id = g_signal_connect (ih, "event", G_CALLBACK (files_changed_cb), self); priv->file_wd = nm_inotify_helper_add_watch (ih, ifcfg_path);