[glib] gnetworkmonitornetlink: Fix potential GMainContext issue
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gnetworkmonitornetlink: Fix potential GMainContext issue
- Date: Wed, 28 Feb 2018 17:40:04 +0000 (UTC)
commit 85f3bc133f258a436fb8018580dd23acf5220a0c
Author: Philip Withnall <withnall endlessm com>
Date: Tue Feb 27 12:48:05 2018 +0000
gnetworkmonitornetlink: Fix potential GMainContext issue
Previously, the GSource would be attached to whatever GMainContext was
the thread default at the time; but that might no longer be the same as
the default at the time of constructing the GNetworkMonitor.
Save the default from construction time, so that source callbacks are
always invoked in the same GMainContext.
Signed-off-by: Philip Withnall <withnall endlessm com>
https://bugzilla.gnome.org/show_bug.cgi?id=793880
gio/gnetworkmonitornetlink.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/gio/gnetworkmonitornetlink.c b/gio/gnetworkmonitornetlink.c
index 942440b5c..d7d9cb79a 100644
--- a/gio/gnetworkmonitornetlink.c
+++ b/gio/gnetworkmonitornetlink.c
@@ -46,6 +46,7 @@ struct _GNetworkMonitorNetlinkPrivate
{
GSocket *sock;
GSource *source, *dump_source;
+ GMainContext *context;
GPtrArray *dump_networks;
};
@@ -75,7 +76,6 @@ g_network_monitor_netlink_init (GNetworkMonitorNetlink *nl)
nl->priv = g_network_monitor_netlink_get_instance_private (nl);
}
-
static gboolean
g_network_monitor_netlink_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -143,11 +143,11 @@ g_network_monitor_netlink_initable_init (GInitable *initable,
}
g_socket_set_blocking (nl->priv->sock, FALSE);
+ nl->priv->context = g_main_context_ref_thread_default ();
nl->priv->source = g_socket_create_source (nl->priv->sock, G_IO_IN, NULL);
g_source_set_callback (nl->priv->source,
(GSourceFunc) read_netlink_messages, nl, NULL);
- g_source_attach (nl->priv->source,
- g_main_context_get_thread_default ());
+ g_source_attach (nl->priv->source, nl->priv->context);
return TRUE;
}
@@ -209,8 +209,7 @@ queue_request_dump (GNetworkMonitorNetlink *nl)
nl->priv->dump_source = g_timeout_source_new (1000);
g_source_set_callback (nl->priv->dump_source,
(GSourceFunc) timeout_request_dump, nl, NULL);
- g_source_attach (nl->priv->dump_source,
- g_main_context_get_thread_default ());
+ g_source_attach (nl->priv->dump_source, nl->priv->context);
}
static void
@@ -457,6 +456,8 @@ g_network_monitor_netlink_finalize (GObject *object)
g_source_unref (nl->priv->dump_source);
}
+ g_clear_pointer (&nl->priv->context, g_main_context_unref);
+
G_OBJECT_CLASS (g_network_monitor_netlink_parent_class)->finalize (object);
}
@@ -465,7 +466,7 @@ g_network_monitor_netlink_class_init (GNetworkMonitorNetlinkClass *nl_class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (nl_class);
- gobject_class->finalize = g_network_monitor_netlink_finalize;
+ gobject_class->finalize = g_network_monitor_netlink_finalize;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]