diff options
author | danielk1977 <danielk1977@noemail.net> | 2004-06-16 10:39:52 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2004-06-16 10:39:52 +0000 |
commit | 8def5ea2034aa9aea0d271b2575492b87f6ad703 (patch) | |
tree | 5cdaa753523c43a58470a1934c07654f5640531e /src | |
parent | 5c4c77878d1bcb101fbc83cf19161a8dbcae2f00 (diff) | |
download | sqlite-8def5ea2034aa9aea0d271b2575492b87f6ad703.tar.gz sqlite-8def5ea2034aa9aea0d271b2575492b87f6ad703.zip |
Fix handling of a failed malloc() in various places (CVS 1605)
FossilOrigin-Name: b739ef2a1b8f7cfee4ab3f4c1319c159bd1e2e40
Diffstat (limited to 'src')
-rw-r--r-- | src/pager.c | 30 | ||||
-rw-r--r-- | src/printf.c | 4 | ||||
-rw-r--r-- | src/trigger.c | 1 | ||||
-rw-r--r-- | src/vdbe.c | 7 |
4 files changed, 25 insertions, 17 deletions
diff --git a/src/pager.c b/src/pager.c index 1a6319bd4..9540fab39 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.129 2004/06/16 07:45:24 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.130 2004/06/16 10:39:39 danielk1977 Exp $ */ #include "os.h" /* Must be first to enable large file support */ #include "sqliteInt.h" @@ -1084,11 +1084,11 @@ int sqlite3pager_open( void *pBusyHandler /* Busy callback */ ){ Pager *pPager; - char *zFullPathname; + char *zFullPathname = 0; int nameLen; OsFile fd; int rc, i; - int tempFile; + int tempFile = 0; int memDb = 0; int readOnly = 0; char zTemp[SQLITE_TEMPNAME_SIZE]; @@ -1105,27 +1105,31 @@ int sqlite3pager_open( rc = SQLITE_OK; }else{ zFullPathname = sqlite3OsFullPathname(zFilename); - rc = sqlite3OsOpenReadWrite(zFullPathname, &fd, &readOnly); - tempFile = 0; + if( zFullPathname ){ + rc = sqlite3OsOpenReadWrite(zFullPathname, &fd, &readOnly); + } } }else{ rc = sqlite3pager_opentemp(zTemp, &fd); zFilename = zTemp; zFullPathname = sqlite3OsFullPathname(zFilename); - tempFile = 1; + if( rc==SQLITE_OK ){ + tempFile = 1; + } } - if( sqlite3_malloc_failed ){ + if( !zFullPathname ){ return SQLITE_NOMEM; } if( rc!=SQLITE_OK ){ - sqliteFree(zFullPathname); - return SQLITE_CANTOPEN; + if( tempFile ) sqlite3OsClose(&fd); + if( zFullPathname ) sqliteFree(zFullPathname); + return rc; } nameLen = strlen(zFullPathname); pPager = sqliteMalloc( sizeof(*pPager) + nameLen*3 + 30 ); if( pPager==0 ){ - sqlite3OsClose(&fd); - sqliteFree(zFullPathname); + if( tempFile ) sqlite3OsClose(&fd); + if( zFullPathname ) sqliteFree(zFullPathname); return SQLITE_NOMEM; } SET_PAGER(pPager); @@ -1735,7 +1739,9 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){ + sizeof(u32) + pPager->nExtra + pPager->memDb*sizeof(PgHistory) ); if( pPg==0 ){ - pager_unwritelock(pPager); + if( !pPager->memDb ){ + pager_unwritelock(pPager); + } pPager->errMask |= PAGER_ERR_MEM; return SQLITE_NOMEM; } diff --git a/src/printf.c b/src/printf.c index 2fdc87dd2..93eefef24 100644 --- a/src/printf.c +++ b/src/printf.c @@ -720,7 +720,9 @@ static char *base_vprintf( if( xRealloc ){ if( sM.zText==sM.zBase ){ sM.zText = xRealloc(0, sM.nChar+1); - memcpy(sM.zText, sM.zBase, sM.nChar+1); + if( sM.zText ){ + memcpy(sM.zText, sM.zBase, sM.nChar+1); + } }else if( sM.nAlloc>sM.nChar+10 ){ sM.zText = xRealloc(sM.zText, sM.nChar+1); } diff --git a/src/trigger.c b/src/trigger.c index 86f0664cf..56c17c1e9 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -79,6 +79,7 @@ void sqlite3BeginTrigger( ** If sqlite3SrcListLookup() returns 0, indicating the table does not ** exist, the error is caught by the block below. */ + if( !pTableName ) goto trigger_cleanup; pTab = sqlite3SrcListLookup(pParse, pTableName); if( pName2->n==0 && pTab && pTab->iDb==1 ){ iDb = 1; diff --git a/src/vdbe.c b/src/vdbe.c index e4931fc0b..527e949ab 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -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.375 2004/06/15 16:51:01 danielk1977 Exp $ +** $Id: vdbe.c,v 1.376 2004/06/16 10:39:52 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -3205,9 +3205,8 @@ case OP_PutStrKey: { pTos->flags = MEM_Null; }else{ pC->pData = sqliteMallocRaw( pC->nData+2 ); - if( pC->pData ){ - memcpy(pC->pData, pTos->z, pC->nData); - } + if( !pC->pData ) goto no_mem; + memcpy(pC->pData, pTos->z, pC->nData); pC->pData[pC->nData] = 0; pC->pData[pC->nData+1] = 0; } |