mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Fix handling of a failed malloc() in various places (CVS 1605)
FossilOrigin-Name: b739ef2a1b8f7cfee4ab3f4c1319c159bd1e2e40
This commit is contained in:
30
src/pager.c
30
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user