From ecb2a9644b4ddcc829fccb8ccda295fd38c2b9fb Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Wed, 2 Jun 2004 06:30:16 +0000 Subject: [PATCH] Fix a segfault in sqlite3OsLock() (CVS 1525) FossilOrigin-Name: 51348b82c4d5801091537b80059d770410774905 --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/os_unix.c | 21 ++++++++++----------- test/thread1.test | 8 ++++---- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index 19a88387c7..9df241e74e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Work\stoward\scombining\sthe\sOP_MakeKey,\sOP_MakeIdxKey,\sand\sOP_MakeRecord\nopcodes\sinto\sone.\s\sThe\swork\sis\sincomplete.\s(CVS\s1524) -D 2004-06-02T01:22:02 +C Fix\sa\ssegfault\sin\ssqlite3OsLock()\s(CVS\s1525) +D 2004-06-02T06:30:16 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -43,7 +43,7 @@ F src/os.h 833b9639720d1602d9bfa4ca69c615ec2bfe625a F src/os_common.h 744286a27de55c52f1b18921e8d17abbf7fafc0f F src/os_mac.c b823874690615ace0dd520d3ad1fe8bfd864b7e0 F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4 -F src/os_unix.c 3dc2868d7ff477323f2eaedda0e05921afb6f124 +F src/os_unix.c 36682ee5e93c2fdad63ff44f7e10ac7d4a39f746 F src/os_unix.h 426e1480f0847a7f8ba22aa9ac5115520875610b F src/os_win.c 92b51a38437b98d8aa3ac05b57c71e1d1092e5be F src/os_win.h 5d41af24caaef6c13a2d8e2399caa1c57d45c84d @@ -148,7 +148,7 @@ F test/tableapi.test e0c4cce61e58343caa84dab33fa6823cb35fe1e1 F test/tclsqlite.test 853e4372004d209e2ff0d4b0b35c91d4f64cd7d8 F test/temptable.test a770ba6308d7f7332fce985086b8e06bed6430c2 F test/tester.tcl fc10520db0d3ce4ef6a8b5ab91bd102fc3f4280a -F test/thread1.test 53f050d5be6932d9430df7756edd379366508ff6 +F test/thread1.test 2fd5c10e82434f6b03be77b61fde5a050668abf2 F test/threadtest1.c f7f896e62ed46feae1dc411114a48c15a0f82ee2 F test/threadtest2.c d94ca4114fd1504f7e0ae724bcd83d4b40931d86 F test/trans.test 45fa0ed87ee487797ea6a30f3ec298a6618531b9 @@ -214,7 +214,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248 F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P b53640ed2232aaf173a71636073477d80407d11f -R 65e9a4b0c9422591cc77c047015d1b85 -U drh -Z f635685494f9f4de060c8aaaeeb301d1 +P 165d69a04cca719dec2b042117f848f153721a1d +R e34294435e363d8121bbbf40938d6dd7 +U danielk1977 +Z cf403c13a566790d4729e792131db901 diff --git a/manifest.uuid b/manifest.uuid index 2e0dc15461..e388ab026b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -165d69a04cca719dec2b042117f848f153721a1d \ No newline at end of file +51348b82c4d5801091537b80059d770410774905 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 3ba8b5b317..d8dca02154 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -61,7 +61,6 @@ */ #include "os_common.h" - /* ** Here is the dirt on POSIX advisory locks: ANSI STD 1003.1 (1996) ** section 6.5.2.2 lines 483 through 490 specify that when a process @@ -649,7 +648,6 @@ int sqlite3OsFileSize(OsFile *id, off_t *pSize){ ** available on the host, then an SQLITE_NOLFS is returned. */ int sqlite3OsReadLock(OsFile *id){ - int rc; return sqlite3OsLock(id, SHARED_LOCK); } @@ -660,7 +658,6 @@ int sqlite3OsReadLock(OsFile *id){ ** available on the host, then an SQLITE_NOLFS is returned. */ int sqlite3OsWriteLock(OsFile *id){ - int rc; return sqlite3OsLock(id, EXCLUSIVE_LOCK); } @@ -715,13 +712,14 @@ int sqlite3OsLock(OsFile *id, int locktype){ (pLock->locktype==SHARED_LOCK || pLock->locktype==RESERVED_LOCK) ){ assert( locktype==SHARED_LOCK ); assert( id->locked==0 ); + assert( pLock->cnt>0 ); id->locked = SHARED_LOCK; pLock->cnt++; id->pOpen->nLock++; goto end_lock; } - lock.l_len = 1L; + lock.l_len = 0L; lock.l_whence = SEEK_SET; /* If control gets to this point, then actually go ahead and make @@ -729,7 +727,6 @@ int sqlite3OsLock(OsFile *id, int locktype){ */ if( locktype==SHARED_LOCK ){ assert( pLock->cnt==0 ); - assert( id->pOpen->nLock==0 ); assert( pLock->locktype==0 ); /* Grab a read-lock on byte 2. This ensures that no other process @@ -753,7 +750,7 @@ int sqlite3OsLock(OsFile *id, int locktype){ rc = (errno==EINVAL) ? SQLITE_NOLFS : SQLITE_BUSY; }else{ id->locked = SHARED_LOCK; - id->pOpen->nLock = 1; + id->pOpen->nLock++; pLock->cnt = 1; } }else{ @@ -782,9 +779,11 @@ int sqlite3OsLock(OsFile *id, int locktype){ } } - id->locked = locktype; - pLock->locktype = locktype; - assert(pLock->locktype==RESERVED_LOCK||(id->pOpen->nLock==1&&pLock->cnt==1)); + if( rc==SQLITE_OK ){ + id->locked = locktype; + pLock->locktype = locktype; + assert( pLock->locktype==RESERVED_LOCK || pLock->cnt==1 ); + } end_lock: sqlite3OsLeaveMutex(); @@ -800,10 +799,10 @@ end_lock: int sqlite3OsUnlock(OsFile *id){ int rc; if( !id->locked ) return SQLITE_OK; + id->locked = 0; sqlite3OsEnterMutex(); assert( id->pLock->cnt!=0 ); if( id->pLock->cnt>1 ){ - id->locked = 0; id->pLock->cnt--; rc = SQLITE_OK; }else{ @@ -819,9 +818,9 @@ int sqlite3OsUnlock(OsFile *id){ rc = SQLITE_OK; id->pLock->cnt = 0; id->pLock->locktype = 0; - id->locked = 0; } } + if( rc==SQLITE_OK ){ /* Decrement the count of locks against this same file. When the ** count reaches zero, close any other file descriptors whose close diff --git a/test/thread1.test b/test/thread1.test index b5b348426c..59f79a7409 100644 --- a/test/thread1.test +++ b/test/thread1.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is multithreading behavior # -# $Id: thread1.test,v 1.3 2004/02/11 02:18:07 drh Exp $ +# $Id: thread1.test,v 1.4 2004/06/02 06:30:18 danielk1977 Exp $ set testdir [file dirname $argv0] @@ -147,12 +147,12 @@ do_test thread1-2.9 { thread_result C } SQLITE_DONE do_test thread1-2.10 { - execsql {SELECT * FROM t2} -} {98 99} -do_test thread1-2.11 { thread_finalize C thread_result C } SQLITE_OK +do_test thread1-2.11 { + execsql {SELECT * FROM t2} +} {98 99} thread_halt * finish_test