[glib-networking] gnome-proxy: use lock to protect settings



commit d5f356e807ab5a523e70845289d8d4e360fde5e0
Author: David Zeuthen <davidz redhat com>
Date:   Wed May 18 10:40:37 2011 -0400

    gnome-proxy: use lock to protect settings
    
    Since it's fine for multiple threads to be calling into our module at
    the same time, we need to protect shared data, like the settings, with
    a lock. The problem was identified in bug 650439. This patch fixes the
    problem.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=650439
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 proxy/gnome/gproxyresolvergnome.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/proxy/gnome/gproxyresolvergnome.c b/proxy/gnome/gproxyresolvergnome.c
index f38448f..b49a32f 100644
--- a/proxy/gnome/gproxyresolvergnome.c
+++ b/proxy/gnome/gproxyresolvergnome.c
@@ -79,6 +79,8 @@ struct _GProxyResolverGnome {
   gchar *ftp_proxy, *socks_authority;
 
   GDBusProxy *pacrunner;
+
+  GMutex *lock;
 };
 
 static void g_proxy_resolver_gnome_iface_init (GProxyResolverInterface *iface);
@@ -114,7 +116,9 @@ gsettings_changed (GSettings   *settings,
 {
   GProxyResolverGnome *resolver = user_data;
 
+  g_mutex_lock (resolver->lock);
   resolver->need_update = TRUE;
+  g_mutex_unlock (resolver->lock);
 }
 
 static void
@@ -155,12 +159,16 @@ g_proxy_resolver_gnome_finalize (GObject *object)
   if (resolver->pacrunner)
     g_object_unref (resolver->pacrunner);
 
+  g_mutex_free (resolver->lock);
+
   G_OBJECT_CLASS (g_proxy_resolver_gnome_parent_class)->finalize (object);
 }
 
 static void
 g_proxy_resolver_gnome_init (GProxyResolverGnome *resolver)
 {
+  resolver->lock = g_mutex_new ();
+
   resolver->proxy_settings = g_settings_new (GNOME_PROXY_SETTINGS_SCHEMA);
   g_signal_connect (resolver->proxy_settings, "changed",
 		    G_CALLBACK (gsettings_changed), resolver);
@@ -180,6 +188,7 @@ g_proxy_resolver_gnome_init (GProxyResolverGnome *resolver)
   resolver->need_update = TRUE;
 }
 
+/* called with lock held */
 static void
 update_settings (GProxyResolverGnome *resolver)
 {
@@ -449,8 +458,10 @@ g_proxy_resolver_gnome_lookup (GProxyResolver  *proxy_resolver,
   const gchar *proxy = "direct://";
   gchar **proxies = NULL;
 
+  g_mutex_lock (resolver->lock);
   if (resolver->need_update)
     update_settings (resolver);
+  g_mutex_unlock (resolver->lock);
 
   if (resolver->mode == G_DESKTOP_PROXY_MODE_NONE)
     goto done;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]