[tracker/tracker-0.10] libtracker-sparql: Fix race between unlock and return in get_internal



commit de1f9bb9588b2dcd021d88ff56c93015dc9e42f5
Author: Jürg Billeter <j bitron ch>
Date:   Wed Mar 16 12:47:33 2011 +0100

    libtracker-sparql: Fix race between unlock and return in get_internal

 src/libtracker-sparql/tracker-connection.vala |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index d12e645..64b6aec 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -88,16 +88,18 @@ public abstract class Tracker.Sparql.Connection : Object {
 	private static new Connection get_internal (bool is_direct_only = false, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError {
 		door.lock ();
 
-		if (singleton != null) {
+		// assign to owned variable to ensure it doesn't get freed between unlock and return
+		var result = singleton;
+		if (result != null) {
 			assert (direct_only == is_direct_only);
 			door.unlock ();
-			return singleton;
+			return result;
 		}
 
 		log_init ();
 
 		/* the True is to assert that direct only is required */
-		Connection result = new Backend (is_direct_only);
+		result = new Backend (is_direct_only);
 		result.init ();
 
 		if (cancellable != null && cancellable.is_cancelled ()) {
@@ -117,16 +119,18 @@ public abstract class Tracker.Sparql.Connection : Object {
 	private async static new Connection get_internal_async (bool is_direct_only = false, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError {
 		door.lock ();
 
-		if (singleton != null) {
+		// assign to owned variable to ensure it doesn't get freed between unlock and return
+		var result = singleton;
+		if (result != null) {
 			assert (direct_only == is_direct_only);
 			door.unlock ();
-			return singleton;
+			return result;
 		}
 
 		log_init ();
 
 		/* the True is to assert that direct only is required */
-		Connection result = new Backend (is_direct_only);
+		result = new Backend (is_direct_only);
 		yield result.init_async ();
 
 		if (cancellable != null && cancellable.is_cancelled ()) {



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