[tracker/tracker-0.10] libtracker-sparql-backend: Fix deadlock on initialization error



commit c6afdebb0eefbfdda886fae275bfe1de91c0838c
Author: Jürg Billeter <j bitron ch>
Date:   Fri May 20 10:17:41 2011 +0200

    libtracker-sparql-backend: Fix deadlock on initialization error

 src/libtracker-sparql-backend/tracker-backend.vala |   26 ++++++++++++-------
 1 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala b/src/libtracker-sparql-backend/tracker-backend.vala
index 2a1ac1a..054a97a 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -23,6 +23,7 @@ interface Tracker.Backend.Status : DBusProxy {
 }
 
 class Tracker.Sparql.Backend : Connection {
+	bool initialized;
 	Tracker.Sparql.Connection direct = null;
 	Tracker.Sparql.Connection bus = null;
 	enum Backend {
@@ -50,21 +51,26 @@ class Tracker.Sparql.Backend : Connection {
 		} catch (GLib.Error e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
+
+		initialized = true;
 	}
 
 	public override void dispose () {
-		door.lock ();
+		// trying to lock on partially initialized instances will deadlock
+		if (initialized) {
+			door.lock ();
 
-		try {
-			// Ensure this instance is not used for any new calls to Tracker.Sparql.Connection.get.
-			// However, a call to Tracker.Sparql.Connection.get between g_object_unref and the
-			// above lock might have increased the reference count of this instance to 2 (or more).
-			// Therefore, we must not clean up direct/bus connection in dispose.
-			if (singleton == this) {
-				singleton = null;
+			try {
+				// Ensure this instance is not used for any new calls to Tracker.Sparql.Connection.get.
+				// However, a call to Tracker.Sparql.Connection.get between g_object_unref and the
+				// above lock might have increased the reference count of this instance to 2 (or more).
+				// Therefore, we must not clean up direct/bus connection in dispose.
+				if (singleton == this) {
+					singleton = null;
+				}
+			} finally {
+				door.unlock ();
 			}
-		} finally {
-			door.unlock ();
 		}
 
 		base.dispose ();



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