Bug 461263 - Race condition exists with mozStorageTransaction
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Fri, 24 Oct 2008 16:50:01 -0400
changeset 20815 4ab369d23d95
parent 20814 6a2e65f15f48
child 20816 d3cdb61f7d29
child 20820 c6d4904201b5
push id3166
push usersdwilsh@shawnwilsher.com
push dateFri, 24 Oct 2008 20:50:31 +0000
treeherdermozilla-central@4ab369d23d95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs461263
milestone1.9.1b2pre
Bug 461263 - Race condition exists with mozStorageTransaction While the race was technically "safe", we could have possibly wrongly tried to commit or rollback. This changeset makes us operate sanely in all conditions. r=bent
storage/public/mozStorageHelper.h
--- a/storage/public/mozStorageHelper.h
+++ b/storage/public/mozStorageHelper.h
@@ -64,23 +64,19 @@ public:
   mozStorageTransaction(mozIStorageConnection* aConnection,
                         PRBool aCommitOnComplete,
                         PRInt32 aType = mozIStorageConnection::TRANSACTION_DEFERRED)
     : mConnection(aConnection),
       mHasTransaction(PR_FALSE),
       mCommitOnComplete(aCommitOnComplete),
       mCompleted(PR_FALSE)
   {
-    if (mConnection) {
-      PRBool transactionInProgress = PR_FALSE;
-      mConnection->GetTransactionInProgress(&transactionInProgress);
-      mHasTransaction = ! transactionInProgress;
-      if (mHasTransaction)
-        mConnection->BeginTransactionAs(aType);
-    }
+    // We won't try to get a transaction if one is already in progress.
+    if (mConnection)
+      mHasTransaction = NS_SUCCEEDED(mConnection->BeginTransactionAs(aType));
   }
   ~mozStorageTransaction()
   {
     if (mConnection && mHasTransaction && ! mCompleted) {
       if (mCommitOnComplete)
         mConnection->CommitTransaction();
       else
         mConnection->RollbackTransaction();