diff options
author | shaneh <shaneh@noemail.net> | 2010-07-20 20:23:38 +0000 |
---|---|---|
committer | shaneh <shaneh@noemail.net> | 2010-07-20 20:23:38 +0000 |
commit | d5a724000be6b04d38601fd8452aca106f5b6fb2 (patch) | |
tree | 3beeae64ebb5b6185e90d386c30474d662af4582 /src | |
parent | 0668f5916e4032e5eeec8bf0a0d43d5a4428b921 (diff) | |
download | sqlite-d5a724000be6b04d38601fd8452aca106f5b6fb2.tar.gz sqlite-d5a724000be6b04d38601fd8452aca106f5b6fb2.zip |
Added fix for race conditions from os_unix.c; added saving of errno in two places.
FossilOrigin-Name: 13ed106c8c279422a6159e28c6887d13a88b7b8b
Diffstat (limited to 'src')
-rw-r--r-- | src/os_win.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/os_win.c b/src/os_win.c index b9de7924e..095131232 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1193,7 +1193,7 @@ static int winDeviceCharacteristics(sqlite3_file *id){ ** ** winShmEnterMutex() ** assert( winShmMutexHeld() ); -** winEnterLeave() +** winShmLeaveMutex() */ static void winShmEnterMutex(void){ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); @@ -1320,13 +1320,19 @@ static int winShmSystemLock( }else{ rc = LockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp); } - rc = (rc!=0) ? SQLITE_OK : SQLITE_BUSY; + + if( rc!= 0 ){ + rc = SQLITE_OK; + }else{ + pFile->lastErrno = GetLastError(); + rc = SQLITE_BUSY; + } OSTRACE(("SHM-LOCK %d %s %s 0x%08lx\n", pFile->hFile.h, rc==SQLITE_OK ? "ok" : "failed", lockType==_SHM_UNLCK ? "UnlockFileEx" : "LockFileEx", - GetLastError())); + pFile->lastErrno)); return rc; } @@ -1457,14 +1463,24 @@ static int winOpenSharedMemory(winFile *pDbFd){ /* Make the new connection a child of the winShmNode */ p->pShmNode = pShmNode; - p->pNext = pShmNode->pFirst; #ifdef SQLITE_DEBUG p->id = pShmNode->nextShmId++; #endif - pShmNode->pFirst = p; pShmNode->nRef++; pDbFd->pShm = p; winShmLeaveMutex(); + + /* The reference count on pShmNode has already been incremented under + ** the cover of the winShmEnterMutex() mutex and the pointer from the + ** new (struct winShm) object to the pShmNode has been set. All that is + ** left to do is to link the new object into the linked list starting + ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex + ** mutex. + */ + sqlite3_mutex_enter(pShmNode->mutex); + p->pNext = pShmNode->pFirst; + pShmNode->pFirst = p; + sqlite3_mutex_leave(pShmNode->mutex); return SQLITE_OK; /* Jump here on any error */ @@ -2072,6 +2088,7 @@ static int winOpen( h, zName, dwDesiredAccess, h==INVALID_HANDLE_VALUE ? "failed" : "ok")); if( h==INVALID_HANDLE_VALUE ){ + pFile->lastErrno = GetLastError(); free(zConverted); if( flags & SQLITE_OPEN_READWRITE ){ return winOpen(pVfs, zName, id, |