]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure the in-memory database can handle malloc failures. (CVS 1169)
authordrh <drh@noemail.net>
Mon, 12 Jan 2004 00:21:52 +0000 (00:21 +0000)
committerdrh <drh@noemail.net>
Mon, 12 Jan 2004 00:21:52 +0000 (00:21 +0000)
FossilOrigin-Name: ba92af182c6c9c6b2e3816006191eedd424cdf1a

manifest
manifest.uuid
src/btree_rb.c

index b05a19d7d341ea4719a3c3908b2376d2a9b2e013..9f9cc8a30325c2cca9db446dee2feec23fa85d16 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sunused\scode\sand\stighten\sexisting\scode\sto\smake\sthe\slibrary\sa\slittle\nsmaller.\s(CVS\s1168)
-D 2004-01-08T02:17:32
+C Make\ssure\sthe\sin-memory\sdatabase\scan\shandle\smalloc\sfailures.\s(CVS\s1169)
+D 2004-01-12T00:21:52
 F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -25,7 +25,7 @@ F src/attach.c 9a3764bbccb1c8b39321630006fbaa0fb8bd1822
 F src/auth.c c59ad0dab501888f8b1fccc25e2f5965d2265116
 F src/btree.c 9ab30f0504ef69ba4cba2f264d8096c5abc2b7b8
 F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048
-F src/btree_rb.c e4084b6a12270674b0cd7034655f55e6a2639c78
+F src/btree_rb.c 8099bcf8645ea0acd698c6a6ca46f2f0a0bca5bb
 F src/build.c a7493c433de5b552f9535d8fa7ed80aaf135491e
 F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
 F src/date.c bb89fdb9c89e367b9a728c58cb96e4823974a2c1
@@ -179,7 +179,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
 F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
-P 5fd581787e88173f0303f870fc956ec9285cca4e
-R 42e0a61dd74faeac7023df4a5dc43247
+P 34a6b7416c6c9bcdf301f5e7b072a0362a746105
+R ac3afb88f5f267ab631548289577e731
 U drh
-Z 17125e9495da03df5ae68d60c6a8dbf2
+Z 3b4e454fa5b8ade83f8e931bb2e45a2d
index 9dd9f1351a9255b9fc80c8651bbfa282f23ec528..a9cf15a1b1d6577decf1826a84d086db03f11706 100644 (file)
@@ -1 +1 @@
-34a6b7416c6c9bcdf301f5e7b072a0362a746105
\ No newline at end of file
+ba92af182c6c9c6b2e3816006191eedd424cdf1a
\ No newline at end of file
index 5ddaaf48b766165fd98bc6ad038c22317cf4a1b0..7f7fa98f33a6d5547c2453b7f9681fcc3489d978 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree_rb.c,v 1.18 2003/12/06 21:43:56 drh Exp $
+** $Id: btree_rb.c,v 1.19 2004/01/12 00:21:52 drh Exp $
 **
 ** This file implements an in-core database using Red-Black balanced
 ** binary trees.
@@ -618,10 +618,12 @@ int sqliteRbtreeOpen(
 ){
   Rbtree **ppRbtree = (Rbtree**)ppBtree;
   *ppRbtree = (Rbtree *)sqliteMalloc(sizeof(Rbtree));
+  if( sqlite_malloc_failed ) goto open_no_mem;
   sqliteHashInit(&(*ppRbtree)->tblHash, SQLITE_HASH_INT, 0);
 
   /* Create a binary tree for the SQLITE_MASTER table at location 2 */
   btreeCreateTable(*ppRbtree, 2);
+  if( sqlite_malloc_failed ) goto open_no_mem;
   (*ppRbtree)->next_idx = 3;
   (*ppRbtree)->pOps = &sqliteRbtreeOps;
   /* Set file type to 4; this is so that "attach ':memory:' as ...."  does not
@@ -630,6 +632,10 @@ int sqliteRbtreeOpen(
   (*ppRbtree)->aMetaData[2] = 4;
   
   return SQLITE_OK;
+
+open_no_mem:
+  *ppBtree = 0;
+  return SQLITE_NOMEM;
 }
 
 /*
@@ -642,11 +648,13 @@ static int memRbtreeCreateTable(Rbtree* tree, int* n)
 
   *n = tree->next_idx++;
   btreeCreateTable(tree, *n);
+  if( sqlite_malloc_failed ) return SQLITE_NOMEM;
 
   /* Set up the rollback structure (if we are not doing this as part of a
    * rollback) */
   if( tree->eTransState != TRANS_ROLLBACK ){
     BtRollbackOp *pRollbackOp = sqliteMalloc(sizeof(BtRollbackOp));
+    if( pRollbackOp==0 ) return SQLITE_NOMEM;
     pRollbackOp->eOp = ROLLBACK_DROP;
     pRollbackOp->iTab = *n;
     btreeLogRollbackOp(tree, pRollbackOp);
@@ -671,6 +679,7 @@ static int memRbtreeDropTable(Rbtree* tree, int n)
 
   if( tree->eTransState != TRANS_ROLLBACK ){
     BtRollbackOp *pRollbackOp = sqliteMalloc(sizeof(BtRollbackOp));
+    if( pRollbackOp==0 ) return SQLITE_NOMEM;
     pRollbackOp->eOp = ROLLBACK_CREATE;
     pRollbackOp->iTab = n;
     btreeLogRollbackOp(tree, pRollbackOp);
@@ -712,6 +721,7 @@ static int memRbtreeCursor(
   RbtCursor *pCur;
   assert(tree);
   pCur = *ppCur = sqliteMalloc(sizeof(RbtCursor));
+  if( sqlite_malloc_failed ) return SQLITE_NOMEM;
   pCur->pTree  = sqliteHashFind(&tree->tblHash, 0, iTable);
   pCur->pRbtree = tree;
   pCur->iTree  = iTable;
@@ -755,6 +765,7 @@ static int memRbtreeInsert(
   /* Take a copy of the input data now, in case we need it for the 
    * replace case */
   pData = sqliteMallocRaw(nData);
+  if( pData==0 ) return SQLITE_NOMEM;
   memcpy(pData, pDataInput, nData);
 
   /* Move the cursor to a node near the key to be inserted. If the key already
@@ -771,8 +782,10 @@ static int memRbtreeInsert(
   memRbtreeMoveto( pCur, pKey, nKey, &match);
   if( match ){
     BtRbNode *pNode = sqliteMalloc(sizeof(BtRbNode));
+    if( pNode==0 ) return SQLITE_NOMEM;
     pNode->nKey = nKey;
     pNode->pKey = sqliteMallocRaw(nKey);
+    if( pNode->pKey==0 ) return SQLITE_NOMEM;
     memcpy(pNode->pKey, pKey, nKey);
     pNode->nData = nData;
     pNode->pData = pData; 
@@ -804,10 +817,12 @@ static int memRbtreeInsert(
     /* Set up a rollback-op in case we have to roll this operation back */
     if( pCur->pRbtree->eTransState != TRANS_ROLLBACK ){
       BtRollbackOp *pOp = sqliteMalloc( sizeof(BtRollbackOp) );
+      if( pOp==0 ) return SQLITE_NOMEM;
       pOp->eOp = ROLLBACK_DELETE;
       pOp->iTab = pCur->iTree;
       pOp->nKey = pNode->nKey;
       pOp->pKey = sqliteMallocRaw( pOp->nKey );
+      if( pOp->pKey==0 ) return SQLITE_NOMEM;
       memcpy( pOp->pKey, pNode->pKey, pOp->nKey );
       btreeLogRollbackOp(pCur->pRbtree, pOp);
     }
@@ -819,9 +834,11 @@ static int memRbtreeInsert(
     /* Set up a rollback-op in case we have to roll this operation back */
     if( pCur->pRbtree->eTransState != TRANS_ROLLBACK ){
       BtRollbackOp *pOp = sqliteMalloc( sizeof(BtRollbackOp) );
+      if( pOp==0 ) return SQLITE_NOMEM;
       pOp->iTab = pCur->iTree;
       pOp->nKey = pCur->pNode->nKey;
       pOp->pKey = sqliteMallocRaw( pOp->nKey );
+      if( pOp->pKey==0 ) return SQLITE_NOMEM;
       memcpy( pOp->pKey, pCur->pNode->pKey, pOp->nKey );
       pOp->nData = pCur->pNode->nData;
       pOp->pData = pCur->pNode->pData;
@@ -924,6 +941,7 @@ static int memRbtreeDelete(RbtCursor* pCur)
    * deletion */
   if( pCur->pRbtree->eTransState != TRANS_ROLLBACK ){
     BtRollbackOp *pOp = sqliteMalloc( sizeof(BtRollbackOp) );
+    if( pOp==0 ) return SQLITE_NOMEM;
     pOp->iTab = pCur->iTree;
     pOp->nKey = pZ->nKey;
     pOp->pKey = pZ->pKey;
@@ -1029,6 +1047,7 @@ static int memRbtreeClearTable(Rbtree* tree, int n)
         sqliteFree( pNode->pData );
       }else{
         BtRollbackOp *pRollbackOp = sqliteMallocRaw(sizeof(BtRollbackOp));
+        if( pRollbackOp==0 ) return SQLITE_NOMEM;
         pRollbackOp->eOp = ROLLBACK_INSERT;
         pRollbackOp->iTab = n;
         pRollbackOp->nKey = pNode->nKey;