Assorted fixes to the handling of various malloc() failures. (CVS 2413)

FossilOrigin-Name: e7844a01c248e8d9204ea9214bec84c81dc07f32
This commit is contained in:
danielk1977 2005-03-21 03:53:38 +00:00
parent 7a8245b525
commit e94ddc9e43
7 changed files with 38 additions and 25 deletions

View File

@ -1,5 +1,5 @@
C Update\sdocs\sto\ssay\sthat\sthe\sdefault_synchronous\spragma\shas\sbeen\sremoved.\nTicket\s#1049.\s(CVS\s2412)
D 2005-03-21T01:31:37
C Assorted\sfixes\sto\sthe\shandling\sof\svarious\smalloc()\sfailures.\s(CVS\s2413)
D 2005-03-21T03:53:38
F Makefile.in 5c00d0037104de2a50ac7647a5f12769795957a3
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -32,11 +32,11 @@ F src/attach.c 3615dbe960cbee4aa5ea300b8a213dad36527b0f
F src/auth.c 18c5a0befe20f3a58a41e3ddd78f372faeeefe1f
F src/btree.c 1d9b2179ccac13970c883da6ae3758cc72978bb0
F src/btree.h 2e2cc923224649337d7217df0dd32b06673ca180
F src/build.c 3c0f4394b0f952083b8aa2791cd699d3b01b02f5
F src/build.c 2dc89aa35a0b4aa318ff9eac941f8412fa6db5df
F src/date.c 2134ef4388256e8247405178df8a61bd60dc180a
F src/delete.c d70d54a84695de92efc05b9db7d3684cd21d9094
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
F src/expr.c 53f854495411eed41e42ec7f174aef64b7918119
F src/expr.c bf7253cd2d828ec8bf321321c2598e4b8918d79b
F src/func.c ff0673a25ec6216934e664bf9f480ae8b2c66936
F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
@ -52,13 +52,13 @@ F src/os_unix.c fba0167576f09e242afd4c4978e1d2944b1da8b5
F src/os_unix.h 40b2fd1d02cfa45d6c3dea25316fd019cf9fcb0c
F src/os_win.c 2bbbe6fbb010763c3fa79d5e951afca9b138c6b5
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c e5000ca94ba2894d249213675318bbc918f97e9c
F src/pager.c f12044be70383010510d06668e3b6c94f78a4726
F src/pager.h 70d496f372163abb6340f474288c4bb9ea962cf7
F src/parse.y 10c0ace9efce31d5a06e03488a4284b9d97abc56
F src/pragma.c 4b20dbc0f4b97f412dc511853d3d0c2e0d4adedc
F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
F src/select.c 69e6093d52e871a243477e9746f820456538dd03
F src/select.c 85695750854188d1eb2d82e0439c99ed6e82645e
F src/shell.c 25b3217d7c64e6497225439d261a253a23efff26
F src/sqlite.h.in c85f6bad9ca7de29f505fe886646cfff7df4c55e
F src/sqliteInt.h 9b2aa887e79b2ecadc24f0b30363b9ec1e5b51e3
@ -75,7 +75,7 @@ F src/update.c 42823d00865c9fe4f01b3c62647858726345a28e
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
F src/util.c 02bc2750336b021b3f10e61538f665c4b0033b5d
F src/vacuum.c 5cf598003191bd91c17a64742bad8e46241698a8
F src/vdbe.c 086e4b42d57af68fceb8c04a6e4eed901777d942
F src/vdbe.c c7973dc0ab52538646018620e3d3c68aa9e6d6c4
F src/vdbe.h 7e307333d74e134eff237bb9d45fe764e544ad6a
F src/vdbeInt.h e80721cd8ff611789e20743eec43363a9fb5a48e
F src/vdbeapi.c 467caa6e6fb9247528b1c7ab9132ae1b4748e8ac
@ -277,7 +277,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b
P 38897a509a98188a06c49c01a71ddf8835c7b607
R 1b4a441146adb0ecc52175bfdcd6efd5
U drh
Z fc644c5b33bbdb85ae450e1f8b341f3b
P 21012bba176035ff69f860936794a6c2a8eac9df
R 277a3536d0f906527a71bca818fa2ef9
U danielk1977
Z c73e8357d1c9dc50a07df66e791e69aa

View File

@ -1 +1 @@
21012bba176035ff69f860936794a6c2a8eac9df
e7844a01c248e8d9204ea9214bec84c81dc07f32

View File

@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.315 2005/03/19 01:41:21 drh Exp $
** $Id: build.c,v 1.316 2005/03/21 03:53:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -2320,7 +2320,7 @@ void sqlite3CreateIndex(
*/
pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 +
(sizeof(int) + sizeof(CollSeq*))*pList->nExpr );
if( pIndex==0 ) goto exit_create_index;
if( sqlite3_malloc_failed ) goto exit_create_index;
pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr];
pIndex->zName = (char*)&pIndex->aiColumn[pList->nExpr];
strcpy(pIndex->zName, zName);

View File

@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.196 2005/03/16 12:15:21 danielk1977 Exp $
** $Id: expr.c,v 1.197 2005/03/21 03:53:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -568,8 +568,8 @@ ExprList *sqlite3ExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){
if( pExpr || pName ){
struct ExprList_item *pItem = &pList->a[pList->nExpr++];
memset(pItem, 0, sizeof(*pItem));
pItem->pExpr = pExpr;
pItem->zName = sqlite3NameFromToken(pName);
pItem->pExpr = pExpr;
}
return pList;

View File

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.196 2005/03/20 22:47:57 drh Exp $
** @(#) $Id: pager.c,v 1.197 2005/03/21 03:53:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -244,6 +244,7 @@ struct Pager {
int pageSize; /* Number of bytes in a page */
int psAligned; /* pageSize rounded up to a multiple of 8 */
int nPage; /* Total number of in-memory pages */
int nMaxPage; /* High water mark of nPage */
int nRef; /* Number of in-memory pages with PgHdr.nRef>0 */
int mxPage; /* Maximum number of pages to hold in cache */
int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */
@ -822,6 +823,7 @@ static PgHdr *pager_lookup(Pager *pPager, Pgno pgno){
*/
static void pager_reset(Pager *pPager){
PgHdr *pPg, *pNext;
if( pPager->errMask ) return;
for(pPg=pPager->pAll; pPg; pPg=pNext){
pNext = pPg->pNextAll;
sqliteFree(pPg);
@ -842,6 +844,7 @@ static void pager_reset(Pager *pPager){
assert( pPager->journalOpen==0 );
}
/*
** When this routine is called, the pager has the journal file open and
** a RESERVED or EXCLUSIVE lock on the database. This routine releases
@ -1630,6 +1633,7 @@ int sqlite3pager_open(
pPager->stmtSize = 0;
pPager->stmtJSize = 0;
pPager->nPage = 0;
pPager->nMaxPage = 0;
pPager->mxPage = 100;
pPager->state = PAGER_UNLOCK;
pPager->errMask = 0;
@ -1921,7 +1925,7 @@ int sqlite3pager_close(Pager *pPager){
if( !MEMDB ){
sqlite3OsUnlock(&pPager->fd, NO_LOCK);
}
assert( pPager->journalOpen==0 );
assert( pPager->errMask || pPager->journalOpen==0 );
break;
}
case PAGER_SHARED: {
@ -1948,8 +1952,14 @@ int sqlite3pager_close(Pager *pPager){
sqliteFree(pPg);
}
TRACE2("CLOSE %d\n", PAGERID(pPager));
assert( pPager->errMask || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
if( pPager->journalOpen ){
sqlite3OsClose(&pPager->jfd);
}
if( pPager->stmtOpen ){
sqlite3OsClose(&pPager->stfd);
}
sqlite3OsClose(&pPager->fd);
assert( pPager->journalOpen==0 );
/* Temp files are automatically deleted by the OS
** if( pPager->tempFile ){
** sqlite3OsDelete(pPager->zFilename);
@ -2338,9 +2348,6 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
+ sizeof(u32) + pPager->nExtra
+ MEMDB*sizeof(PgHistory) );
if( pPg==0 ){
if( !MEMDB ){
pager_unwritelock(pPager);
}
pPager->errMask |= PAGER_ERR_MEM;
return SQLITE_NOMEM;
}
@ -2352,6 +2359,10 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
pPg->pNextAll = pPager->pAll;
pPager->pAll = pPg;
pPager->nPage++;
if( pPager->nPage>pPager->nMaxPage ){
assert( pPager->nMaxPage==(pPager->nPage-1) );
pPager->nMaxPage++;
}
}else{
/* Find a page to recycle. Try to locate a page that does not
** require us to do an fsync() on the journal.

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.241 2005/02/12 08:59:57 danielk1977 Exp $
** $Id: select.c,v 1.242 2005/03/21 03:53:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
@ -890,6 +890,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
zName = sqlite3MPrintf("column%d", i+1);
}
sqlite3Dequote(zName);
if( sqlite3_malloc_failed ) return 0;
/* Make sure the column name is unique. If the name is not unique,
** append a integer to the name so that it becomes unique.
@ -955,7 +956,7 @@ static int prepSelectStmt(Parse *pParse, Select *p){
Table *pTab;
struct SrcList_item *pFrom;
if( p==0 || p->pSrc==0 ) return 1;
if( p==0 || p->pSrc==0 || sqlite3_malloc_failed ) return 1;
pTabList = p->pSrc;
pEList = p->pEList;

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.459 2005/03/17 03:52:48 drh Exp $
** $Id: vdbe.c,v 1.460 2005/03/21 03:53:38 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -479,6 +479,7 @@ int sqlite3VdbeExec(
for(pc=p->pc; rc==SQLITE_OK; pc++){
assert( pc>=0 && pc<p->nOp );
assert( pTos<=&p->aStack[pc] );
if( sqlite3_malloc_failed ) goto no_mem;
#ifdef VDBE_PROFILE
origPc = pc;
start = hwtime();