GSettings Registry Backend: Init cache_lock Earlier

In commit 8ff5668, we are subscribing the GSettings backend later, but this
meant that we need to initialize cache_lock earlier, as we might try to
use that lock before a change notification is issued to subscribe the
backend, which would then cause an access violation if we are trying to
read GSettings values, as that lock is used to access the Windows Registry.

Initialize cache_lock once we initialize the GSettings Registry backend,
and delete it upon finalize, so that g_settings_read_from_backend() can
proceed normally, even if the GSettings backend is not yet subscribed.

https://bugzilla.gnome.org/show_bug.cgi?id=740413
This commit is contained in:
Chun-wei Fan 2014-11-20 18:34:21 +08:00
parent 5c68fc9f93
commit f6bbd19beb

View File

@ -1654,9 +1654,6 @@ watch_start (GRegistryBackend *self)
g_return_val_if_fail (self->watch == NULL, FALSE); g_return_val_if_fail (self->watch == NULL, FALSE);
self->cache_lock = g_slice_new (CRITICAL_SECTION);
InitializeCriticalSection (self->cache_lock);
watch = g_slice_new (WatchThreadState); watch = g_slice_new (WatchThreadState);
watch->owner = G_SETTINGS_BACKEND (self); watch->owner = G_SETTINGS_BACKEND (self);
@ -1685,8 +1682,6 @@ watch_start (GRegistryBackend *self)
return TRUE; return TRUE;
fail_2: fail_2:
DeleteCriticalSection (self->cache_lock);
g_slice_free (CRITICAL_SECTION, self->cache_lock);
DeleteCriticalSection (watch->message_lock); DeleteCriticalSection (watch->message_lock);
g_slice_free (CRITICAL_SECTION, watch->message_lock); g_slice_free (CRITICAL_SECTION, watch->message_lock);
CloseHandle (watch->message_sent_event); CloseHandle (watch->message_sent_event);
@ -1720,9 +1715,7 @@ watch_stop_unlocked (GRegistryBackend *self)
LeaveCriticalSection (watch->message_lock); LeaveCriticalSection (watch->message_lock);
DeleteCriticalSection (watch->message_lock); DeleteCriticalSection (watch->message_lock);
DeleteCriticalSection (self->cache_lock);
g_slice_free (CRITICAL_SECTION, watch->message_lock); g_slice_free (CRITICAL_SECTION, watch->message_lock);
g_slice_free (CRITICAL_SECTION, self->cache_lock);
CloseHandle (watch->message_sent_event); CloseHandle (watch->message_sent_event);
CloseHandle (watch->message_received_event); CloseHandle (watch->message_received_event);
CloseHandle (watch->thread); CloseHandle (watch->thread);
@ -1936,6 +1929,9 @@ g_registry_backend_finalize (GObject *object)
watch_stop_unlocked (self); watch_stop_unlocked (self);
} }
DeleteCriticalSection (self->cache_lock);
g_slice_free (CRITICAL_SECTION, self->cache_lock);
g_free (self->base_path); g_free (self->base_path);
} }
@ -1970,5 +1966,8 @@ g_registry_backend_init (GRegistryBackend *self)
item->ref_count = 1; item->ref_count = 1;
self->cache_root = g_node_new (item); self->cache_root = g_node_new (item);
self->cache_lock = g_slice_new (CRITICAL_SECTION);
InitializeCriticalSection (self->cache_lock);
self->watch = NULL; self->watch = NULL;
} }