]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Memory allocation failure in Bitvec are probably all benign. Still, add
authordrh <drh@noemail.net>
Fri, 2 Jan 2009 21:39:39 +0000 (21:39 +0000)
committerdrh <drh@noemail.net>
Fri, 2 Jan 2009 21:39:39 +0000 (21:39 +0000)
code to check this, just to be sure. (CVS 6104)

FossilOrigin-Name: 4688e1c8b1203c3538aa862421ed344888059fe2

manifest
manifest.uuid
src/bitvec.c
src/pager.c
src/sqliteInt.h

index 3886962062f3a42f78ef0f517f4af7469df8fe18..5f64a639c9454dbbada39a61c9459ac204388b35 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Reinitialize\spage\s1\sof\sthe\sdatabase\sfile\sfollowing\sa\sROLLBACK\sTO\sof\sa\ntransactional\sSAVEPOINT\son\san\sinitially\sempty\sdatabase.\s(CVS\s6103)
-D 2009-01-02T21:08:09
+C Memory\sallocation\sfailure\sin\sBitvec\sare\sprobably\sall\sbenign.\s\sStill,\sadd\ncode\sto\scheck\sthis,\sjust\sto\sbe\ssure.\s(CVS\s6104)
+D 2009-01-02T21:39:39
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 05461a9b5803d5ad10c79f989801e9fd2cc3e592
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -101,7 +101,7 @@ F src/alter.c 7eee66a6de2605a4aa6a85be6b4688b89e0f48ff
 F src/analyze.c c86fd6a1425b22b3a46ce72ad403e4280026364f
 F src/attach.c 1c35f95da3c62d19de75b44cfefd12c81c1791b3
 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
-F src/bitvec.c 4300d311b17fb3c1476623fd895a8feac02a0b08
+F src/bitvec.c a97d315fc7c0ec54fabd8859a45bd4e8e0d16b0b
 F src/btmutex.c 63c5cc4ad5715690767ffcb741e185d7bc35ec1a
 F src/btree.c b0cf3e7273ba20fe280fc7c889f972419562076d
 F src/btree.h 4f141cf748d2ee7c6d7fc175f64f87a45cd44113
@@ -142,7 +142,7 @@ F src/os_common.h 24525d8b7bce66c374dfc1810a6c9043f3359b60
 F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
 F src/os_unix.c e6eacc7ec735ded605fefcbaf250058baa8feb12
 F src/os_win.c 496e3ceb499aedc63622a89ef76f7af2dd902709
-F src/pager.c 151cc07325103ac217cd483e2aa67cb128aae1eb
+F src/pager.c e82987578519a149e8bdf7f5c2a330d879914b4e
 F src/pager.h 75396879910768a0af03a4af8413e798d84c096f
 F src/parse.y 4d0e33a702dc3ea7b69d8ae1914b3fbd32e46057
 F src/pcache.c 16dc8da6e6ba6250f8dfd9ee46036db1cbceedc6
@@ -158,7 +158,7 @@ F src/select.c 6c2a5675c21bef11d8160f3dc97e1adfbf26bbb9
 F src/shell.c 65d19f8996a160f288087e31810f24025439c62a
 F src/sqlite.h.in 6cd2489e40fe97ba58c60044a4ced377e08b6d09
 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
-F src/sqliteInt.h db087faf9556d61a05baf6f935307b4ce4b8af11
+F src/sqliteInt.h e95ddac4bb83570191c3713dfa31796aeb47cd3a
 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
 F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
 F src/table.c 23db1e5f27c03160987c122a078b4bb51ef0b2f8
@@ -691,7 +691,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 78dd7909da15a9b2cbcdb9cbe86798cfc24f3230
-R 43c17ab6466f886c67eb16e151d17eac
+P 3e9efb763875b20c856d748c19e449080a3ae97c
+R fbb0f228e00217f5f89f33568f0e8c54
 U drh
-Z 7692693fe330733d99a3256112d00dbb
+Z 9cf41e60e2f6cdb3d7a7b42a85a7af92
index f18bbbbd7563b21cd0c3694ab7daf190e5280521..c4aaabf331bc9220f0a51cc2a4748be744f0db40 100644 (file)
@@ -1 +1 @@
-3e9efb763875b20c856d748c19e449080a3ae97c
\ No newline at end of file
+4688e1c8b1203c3538aa862421ed344888059fe2
\ No newline at end of file
index 3a28a8004fb8d2e656c03de7fc72b08369b068b4..4098e57d0cce6b3edc1bcad2a8c32deac4b2707c 100644 (file)
@@ -34,7 +34,7 @@
 ** start of a transaction, and is thus usually less than a few thousand,
 ** but can be as large as 2 billion for a really big database.
 **
-** @(#) $Id: bitvec.c,v 1.9 2008/11/19 18:30:35 shane Exp $
+** @(#) $Id: bitvec.c,v 1.10 2009/01/02 21:39:39 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -174,9 +174,7 @@ int sqlite3BitvecSet(Bitvec *p, u32 i){
     u32 bin = i/p->iDivisor;
     i = i%p->iDivisor;
     if( p->u.apSub[bin]==0 ){
-      sqlite3BeginBenignMalloc();
       p->u.apSub[bin] = sqlite3BitvecCreate( p->iDivisor );
-      sqlite3EndBenignMalloc();
       if( p->u.apSub[bin]==0 ) return SQLITE_NOMEM;
     }
     p = p->u.apSub[bin];
index 25f4699a9d49b7958ac7b170a7fb564027a40a38..292e86fa39bab4829e7a04157ba5326a83f20b85 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.527 2009/01/02 21:08:09 drh Exp $
+** @(#) $Id: pager.c,v 1.528 2009/01/02 21:39:39 drh Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
@@ -960,15 +960,17 @@ static void releaseAllSavepoint(Pager *pPager){
 ** all open savepoints.
 */
 static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
-  int ii;
+  int ii;                   /* Loop counter */
+  int rc = SQLITE_OK;       /* Result code */
+
   for(ii=0; ii<pPager->nSavepoint; ii++){
     PagerSavepoint *p = &pPager->aSavepoint[ii];
     if( pgno<=p->nOrig ){
-      /* TODO: malloc() failure handling */
-      sqlite3BitvecSet(p->pInSavepoint, pgno);
+      rc |= sqlite3BitvecSet(p->pInSavepoint, pgno);
+      assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
     }
   }
-  return SQLITE_OK;
+  return rc;
 }
 
 /*
@@ -3360,8 +3362,14 @@ static int pager_write(PgHdr *pPg){
 
         pPager->nRec++;
         assert( pPager->pInJournal!=0 );
-        sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
-        addToSavepointBitvecs(pPager, pPg->pgno);
+        rc = sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
+        testcase( rc==SQLITE_NOMEM );
+        assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
+        rc |= addToSavepointBitvecs(pPager, pPg->pgno);
+        if( rc!=SQLITE_OK ){
+          assert( rc==SQLITE_NOMEM );
+          return rc;
+        }
       }else{
         if( !pPager->journalStarted && !pPager->noSync ){
           pPg->flags |= PGHDR_NEED_SYNC;
@@ -3392,7 +3400,11 @@ static int pager_write(PgHdr *pPg){
       }
       pPager->stmtNRec++;
       assert( pPager->nSavepoint>0 );
-      addToSavepointBitvecs(pPager, pPg->pgno);
+      rc = addToSavepointBitvecs(pPager, pPg->pgno);
+      if( rc!=SQLITE_OK ){
+        assert( rc==SQLITE_NOMEM );
+        return rc;
+      }
     }
   }
 
@@ -3594,6 +3606,7 @@ int sqlite3PagerDontWrite(DbPage *pDbPage){
 */
 void sqlite3PagerDontRollback(DbPage *pPg){
   Pager *pPager = pPg->pPager;
+  TESTONLY( int rc; )  /* Return value from sqlite3BitvecSet() */
 
   assert( pPager->state>=PAGER_RESERVED );
 
@@ -3628,9 +3641,22 @@ void sqlite3PagerDontRollback(DbPage *pPg){
   /* assert( !pPg->inJournal && (int)pPg->pgno <= pPager->dbOrigSize ); */
 
   assert( pPager->pInJournal!=0 );
-  sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
   pPg->flags &= ~PGHDR_NEED_READ;
-  addToSavepointBitvecs(pPager, pPg->pgno);
+
+  /* Failure to set the bits in the InJournal bit-vectors is benign.
+  ** It merely means that we might do some extra work to journal a page
+  ** that does not need to be journal.  Nevertheless, be sure to test the
+  ** case where a malloc error occurs while trying to set a bit in a 
+  ** bit vector.
+  */
+  sqlite3BeginBenignMalloc();
+  TESTONLY( rc = ) sqlite3BitvecSet(pPager->pInJournal, pPg->pgno);
+  testcase( rc==SQLITE_NOMEM );
+  TESTONLY( rc = ) addToSavepointBitvecs(pPager, pPg->pgno);
+  testcase( rc==SQLITE_NOMEM );
+  sqlite3EndBenignMalloc();
+
+
   PAGERTRACE3("DONT_ROLLBACK page %d of %d\n", pPg->pgno, PAGERID(pPager));
   IOTRACE(("GARBAGE %p %d\n", pPager, pPg->pgno))
 }
index 64b4a12d541a04b9d4f4f1a102359e3f9be8e3a9..43721a0d33a70ff6e6cff9a9b6aa366643bf68b7 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.817 2009/01/02 17:33:46 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.818 2009/01/02 21:39:39 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
 #ifdef SQLITE_COVERAGE_TEST
   void sqlite3Coverage(int);
 # define testcase(X)  if( X ){ sqlite3Coverage(__LINE__); }
+# define TESTONLY(X)  X
 #else
 # define testcase(X)
+# define TESTONLY(X)
 #endif
 
 /*