From c89b238b4a03e08ca8c793c5689948b1fa9c2722 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Fri, 15 May 2009 14:29:28 +0200 Subject: [PATCH] Avoid deadlock when pulling resolved record from cache When the host has already been resolved and is present in the cache, it's returned immediately. But we always started the mainloop even if it was quit before, resulting in endless waiting for an event which had been received before that. --- common/gvfsdnssdresolver.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/common/gvfsdnssdresolver.c b/common/gvfsdnssdresolver.c index 7794042..957d2cb 100644 --- a/common/gvfsdnssdresolver.c +++ b/common/gvfsdnssdresolver.c @@ -1249,14 +1249,21 @@ g_vfs_dns_sd_resolver_resolve_sync (GVfsDnsSdResolver *resolver, g_return_val_if_fail (G_VFS_IS_DNS_SD_RESOLVER (resolver), FALSE); data = g_new0 (ResolveDataSync, 1); - data->loop = g_main_loop_new (NULL, FALSE); + /* mark the main loop as running to have an indication whether + * g_main_loop_quit() was called before g_main_loop_run() + */ + data->loop = g_main_loop_new (NULL, TRUE); g_vfs_dns_sd_resolver_resolve (resolver, cancellable, (GAsyncReadyCallback) resolve_sync_cb, data); - g_main_loop_run (data->loop); + /* start the loop only if it wasn't quit before + * (i.e. in case when pulling the record from cache) + */ + if (g_main_loop_is_running (data->loop)) + g_main_loop_run (data->loop); ret = data->ret; if (data->error != NULL) -- 1.6.2.2