Merge branch 'feature/sess_db_destroy' into 3.1-stable
diff --git a/system/libraries/Session/drivers/Session_database_driver.php b/system/libraries/Session/drivers/Session_database_driver.php
index 31f5a46..b519b78 100644
--- a/system/libraries/Session/drivers/Session_database_driver.php
+++ b/system/libraries/Session/drivers/Session_database_driver.php
@@ -208,12 +208,8 @@
 		// Prevent previous QB calls from messing with our queries
 		$this->_db->reset_query();
 
-		if ($this->_lock === FALSE)
-		{
-			return $this->_fail();
-		}
 		// Was the ID regenerated?
-		elseif ($session_id !== $this->_session_id)
+		if (isset($this->_session_id) && $session_id !== $this->_session_id)
 		{
 			if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id))
 			{
@@ -223,6 +219,10 @@
 			$this->_row_exists = FALSE;
 			$this->_session_id = $session_id;
 		}
+		elseif ($this->_lock === FALSE)
+		{
+			return $this->_fail();
+		}
 
 		if ($this->_row_exists === FALSE)
 		{