]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Disable automatic invocation of sqlite3_release_memory() when a malloc() fails
authordanielk1977 <danielk1977@noemail.net>
Thu, 5 Jan 2006 13:48:29 +0000 (13:48 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Thu, 5 Jan 2006 13:48:29 +0000 (13:48 +0000)
in those cases where the global mutex is held. (CVS 2860)

FossilOrigin-Name: 6fdbb8b771e490f0d791326689245302c4fe18f5

manifest
manifest.uuid
src/main.c
src/os_unix.c
src/pager.c
src/sqliteInt.h
test/all.test

index 256733b7a82da8c35a22be517a71045ca9694985..e8f7f2f1b4f534654a46094085ce1336e2f1598f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\sshared\sschema/pager\smodifications.\sVery\sfew\stests\sso\sfar.\s(CVS\s2859)
-D 2006-01-05T11:34:33
+C Disable\sautomatic\sinvocation\sof\ssqlite3_release_memory()\swhen\sa\smalloc()\sfails\nin\sthose\scases\swhere\sthe\sglobal\smutex\sis\sheld.\s(CVS\s2860)
+D 2006-01-05T13:48:29
 F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -48,18 +48,18 @@ F src/hash.c 8747cf51d12de46512880dfcf1b68b4e24072863
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c d167f9d41932ddaff9162f116e2abc514b0680b6
 F src/legacy.c 59757d857ab95fcbb0ac27692d3201e35f093dd7
-F src/main.c 3a9689e4127ad7d4d417ff4e0bed2dd2b76ea445
+F src/main.c c1d8d2022a65104c847880882fbce9ba32381530
 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
 F src/os.c 7b4a002d9c9421580276db55d2329636a604e8ef
 F src/os.h cc99e1515696728ba64c77fffa781ebadea34619
 F src/os_common.h d0b1f2f32926e9b6db7886a7f43008b596a9e926
 F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
 F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
-F src/os_unix.c e4fbf1370e1a03875ebb3239316fa8eb8476258b
+F src/os_unix.c d52d87a06ce62c7c6b9f7dcb7da1248737397765
 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
 F src/os_win.c 7e2d09f81cb83709b9774ac6be80fa3cb08ac86d
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
-F src/pager.c 681b4e39d581ead8fd54283176138bec924a4bae
+F src/pager.c 07509ddb478f5a70f9ff53607ab8a44456c22811
 F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
 F src/parse.y 58258759fabdd48f1d2561e276097290b1ea2680
 F src/pragma.c 4af4041a88d41421b8ff2e5574d82d7b9d1e35b1
@@ -69,7 +69,7 @@ F src/random.c ff5e9a8cad790e2a51cd4d2e7737dc8540e09d1d
 F src/select.c 7a78520fcd79daccd4e33721dbc977d2e5c5d95a
 F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
 F src/sqlite.h.in ba3a29daa6a16e054191ccb384a981964e882a1d
-F src/sqliteInt.h 5117ce283868de7010e62ec1a80ce1162575c184
+F src/sqliteInt.h 6f29c97703b1a1e032916b0bab83efe9b2734984
 F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
 F src/tclsqlite.c 0386460a4c017d49d729d44cdcb3fb3ffb2503e0
 F src/test1.c 988dbac66c3ca92d69fbe0283d77e86cd6f73ce8
@@ -94,7 +94,7 @@ F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c deba8d6e3727643924b210a8c531a496c2b8d386
 F src/where.c 3ec45076e7cce523aad34eaf9bd119237b56942a
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
-F test/all.test 18602f8cd97d5741574dee7288e1f5f427f12825
+F test/all.test 90cf64bb655e3d474b0dda04e63ece03e36b0ce2
 F test/alter.test b94b640063e725d062b2997bd2810ac39195c718
 F test/alter2.test cc0b8832e4e98605dbc26910efd4bb89abe59cb2
 F test/alter3.test 6e144ea3dcc395afcc28e794bb532be83dc8fdcb
@@ -336,7 +336,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P cb9095ac52e76926f274678ef55ebb9df4b9fcac
-R a8dde2ab271da0ac5619066fd6022d05
+P deeda0dc06c1595aedd8d06a0c4e88a8abf78cf7
+R 9d12b452805846233d53c41b43a70bb0
 U danielk1977
-Z 0d100378c01552c949846ec200b31003
+Z f6fa8bc04dbc256a46d97346ce8d34cd
index a50e26f5548e5eabff5c9269b49d3202b4c611be..42c4c88def537037c7d54da52b206a85607a4a1e 100644 (file)
@@ -1 +1 @@
-deeda0dc06c1595aedd8d06a0c4e88a8abf78cf7
\ No newline at end of file
+6fdbb8b771e490f0d791326689245302c4fe18f5
\ No newline at end of file
index 9858e6efc00173a4169f5db1fd854d1f86ebc51a..ebf2a3480c550fef31c0a2a56659d94f07e2363f 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.314 2006/01/05 11:34:34 danielk1977 Exp $
+** $Id: main.c,v 1.315 2006/01/05 13:48:29 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -211,26 +211,6 @@ int sqlite3_close(sqlite3 *db){
     sqlite3ValueFree(db->pErr);
   }
 
-#if 0 
-#ifndef SQLITE_OMIT_GLOBALRECOVER
-  {
-    sqlite3 *pPrev;
-    sqlite3Os.xEnterMutex();
-    pPrev = pDbList;
-    while( pPrev && pPrev->pNext!=db ){
-      pPrev = pPrev->pNext;
-    }
-    if( pPrev ){
-      pPrev->pNext = db->pNext;
-    }else{
-      assert( pDbList==db );
-      pDbList = db->pNext;
-    }
-    sqlite3Os.xLeaveMutex();
-  }
-#endif
-#endif
-
   db->magic = SQLITE_MAGIC_ERROR;
   sqliteFree(db->aDb[1].pSchema);
   sqliteFree(db);
index de7f0729c65db8bd265121d370509b52f523027b..f2ac94e12684a55adeda5e5eeaa0599d1a3fec58 100644 (file)
@@ -485,8 +485,14 @@ static int findLockInfo(
   struct stat statbuf;
   struct lockInfo *pLock;
   struct openCnt *pOpen;
+  SqliteTsd *pTsd = sqlite3Tsd();
   rc = fstat(fd, &statbuf);
   if( rc!=0 ) return 1;
+
+  /* Disable the sqlite3_release_memory() function */
+  assert( !pTsd->disableReleaseMemory );
+  pTsd->disableReleaseMemory = 1;
+
   memset(&key1, 0, sizeof(key1));
   key1.dev = statbuf.st_dev;
   key1.ino = statbuf.st_ino;
@@ -503,7 +509,10 @@ static int findLockInfo(
   if( pLock==0 ){
     struct lockInfo *pOld;
     pLock = sqliteMallocRaw( sizeof(*pLock) );
-    if( pLock==0 ) return 1;
+    if( pLock==0 ){
+      rc = 1;
+      goto exit_findlockinfo;
+    }
     pLock->key = key1;
     pLock->nRef = 1;
     pLock->cnt = 0;
@@ -512,7 +521,8 @@ static int findLockInfo(
     if( pOld!=0 ){
       assert( pOld==pLock );
       sqliteFree(pLock);
-      return 1;
+      rc = 1;
+      goto exit_findlockinfo;
     }
   }else{
     pLock->nRef++;
@@ -524,7 +534,8 @@ static int findLockInfo(
     pOpen = sqliteMallocRaw( sizeof(*pOpen) );
     if( pOpen==0 ){
       releaseLockInfo(pLock);
-      return 1;
+      rc = 1;
+      goto exit_findlockinfo;
     }
     pOpen->key = key2;
     pOpen->nRef = 1;
@@ -536,13 +547,18 @@ static int findLockInfo(
       assert( pOld==pOpen );
       sqliteFree(pOpen);
       releaseLockInfo(pLock);
-      return 1;
+      rc = 1;
+      goto exit_findlockinfo;
     }
   }else{
     pOpen->nRef++;
   }
   *ppOpen = pOpen;
-  return 0;
+
+exit_findlockinfo:
+  /* Re-enable sqlite3_release_memory() */
+  pTsd->disableReleaseMemory = 0;
+  return rc;
 }
 
 /*
@@ -1371,6 +1387,7 @@ static int unixUnlock(OsFile *id, int locktype){
 ** Close a file.
 */
 static int unixClose(OsFile **pId){
+  SqliteTsd *pTsd = sqlite3Tsd();
   unixFile *id = (unixFile*)*pId;
   if( !id ) return SQLITE_OK;
   if( CHECK_THREADID(id) ) return SQLITE_MISUSE;
@@ -1378,6 +1395,11 @@ static int unixClose(OsFile **pId){
   if( id->dirfd>=0 ) close(id->dirfd);
   id->dirfd = -1;
   sqlite3Os.xEnterMutex();
+
+  /* Disable the sqlite3_release_memory() function */
+  assert( !pTsd->disableReleaseMemory );
+  pTsd->disableReleaseMemory = 1;
+
   if( id->pOpen->nLock ){
     /* If there are outstanding locks, do not actually close the file just
     ** yet because that would clear those locks.  Instead, add the file
@@ -1400,6 +1422,10 @@ static int unixClose(OsFile **pId){
   }
   releaseLockInfo(id->pLock);
   releaseOpenCnt(id->pOpen);
+
+  /* Disable the sqlite3_release_memory() function */
+  pTsd->disableReleaseMemory = 0;
+
   sqlite3Os.xLeaveMutex();
   id->isOpen = 0;
   TRACE2("CLOSE   %-3d\n", id->h);
index 40df13f2265030b27db5bc564d291850de187da7..bb979cad721958c6f3a06129a5796ab103b8a2ca 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.229 2005/12/30 16:28:02 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.230 2006/01/05 13:48:29 danielk1977 Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
@@ -2460,6 +2460,16 @@ int sqlite3pager_release_memory(int nReq){
   int nReleased = 0;
   int i;
 
+  /* If the disableReleaseMemory memory flag is set, this operation is
+  ** a no-op; zero bytes of memory are freed. The flag is set before
+  ** malloc() is called while the global mutex (see sqlite3Os.xEnterMutex) 
+  ** is held. Because some of the code invoked by this function may also
+  ** try to obtain the mutex, proceding may cause a deadlock. 
+  */
+  if( pTsd->disableReleaseMemory ){
+    return 0;
+  }
+
   /* Outermost loop runs for at most two iterations. First iteration we
   ** try to find memory that can be released without calling fsync(). Second
   ** iteration (which only runs if the first failed to free nReq bytes of
index 3cc6d6fdfb5d1c30c925caea10ce29b63544623a..24f92fda21d664bfda123398434ec16a4e9f445a 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.448 2006/01/05 11:34:34 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.449 2006/01/05 13:48:29 danielk1977 Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -282,6 +282,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
 struct SqliteTsd {
   u8 isInit;               /* True if structure has been initialised */
   u8 mallocFailed;         /* True after a malloc() has failed */
+  u8 disableReleaseMemory; /* True to make sqlite3_release_memory() a no-op */
 
 #ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
   i64 nSoftHeapLimit;      /* -ve for unlimited */
index 2bf98702b9014b37abfd94bc5d6361df410a1715..e150e87c1039e033679ebfc49fc746980225c556 100644 (file)
@@ -10,7 +10,7 @@
 #***********************************************************************
 # This file runs all tests.
 #
-# $Id: all.test,v 1.32 2006/01/05 11:34:34 danielk1977 Exp $
+# $Id: all.test,v 1.33 2006/01/05 13:48:29 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -56,11 +56,6 @@ set EXCLUDE {
   malloc.test
   misuse.test
   memleak.test
-
-  malloc2.test
-  malloc3.test
-  malloc4.test
-  malloc5.test
 }
 
 # Test files btree2.test and btree4.test don't work if the