Improve memory allocation error handling on WinCE.
FossilOrigin-Name: 09dfc0c915ec2f0c5f633a3485d47cad15eec4dc
This commit is contained in:
parent
a173eab75f
commit
7e87eae901
17
manifest
17
manifest
@ -1,5 +1,5 @@
|
||||
C Add\sextended\serror\scodes\sfor\sall\sSQLITE_CONSTRAINT\serrors.
|
||||
D 2013-02-11T13:47:39.039
|
||||
C Improve\smemory\sallocation\serror\shandling\son\sWinCE.
|
||||
D 2013-02-12T09:46:48.810
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -161,7 +161,7 @@ F src/os.c e1acdc09ff3ac2412945cca9766e2dcf4675f31c
|
||||
F src/os.h 027491c77d2404c0a678bb3fb06286f331eb9b57
|
||||
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
||||
F src/os_unix.c dfdc04b126f7b05dcb2e2cc5c1262f98acbb49d9
|
||||
F src/os_win.c d19aae35a7b06f3dbaebb033eff5a68903856791
|
||||
F src/os_win.c e988c2de4266fbb3b8c58e4b5550a2e17f541327
|
||||
F src/pager.c 4092c907222cfd451c74fe6bd2fd64b342f7190f
|
||||
F src/pager.h 1109a06578ec5574dc2c74cf8d9f69daf36fe3e0
|
||||
F src/parse.y 5d5e12772845805fdfeb889163516b84fbb9ae95
|
||||
@ -1034,7 +1034,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||
P 4a7b4ee011fea911b981206c242e3d5553303b52 3f67437536591a1b0742a25b983707933aaa16d5
|
||||
R 3e5bf93d528119a300b3cfbe9643fae2
|
||||
U drh
|
||||
Z 3a7fd1a084dac5a1a2f87b7b22126c80
|
||||
P 939d8282748b00a7032cdd72e5d3bf3086ebfc97
|
||||
R c401d0f64d91c49092b5d167ad9b4b56
|
||||
T *branch * wince
|
||||
T *sym-wince *
|
||||
T -sym-trunk *
|
||||
U mistachkin
|
||||
Z 7666d75ce0c62ebd1a3a9ee46fc0b14d
|
||||
|
@ -1 +1 @@
|
||||
939d8282748b00a7032cdd72e5d3bf3086ebfc97
|
||||
09dfc0c915ec2f0c5f633a3485d47cad15eec4dc
|
46
src/os_win.c
46
src/os_win.c
@ -988,7 +988,7 @@ static const char *winNextSystemCall(sqlite3_vfs *p, const char *zName){
|
||||
** (if available).
|
||||
*/
|
||||
|
||||
void sqlite3_win32_write_debug(char *zBuf, int nBuf){
|
||||
void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
|
||||
char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE];
|
||||
int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
|
||||
if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
|
||||
@ -1670,15 +1670,17 @@ static void winceMutexAcquire(HANDLE h){
|
||||
** Create the mutex and shared memory used for locking in the file
|
||||
** descriptor pFile
|
||||
*/
|
||||
static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
|
||||
static int winceCreateLock(const char *zFilename, winFile *pFile){
|
||||
LPWSTR zTok;
|
||||
LPWSTR zName;
|
||||
DWORD lastErrno;
|
||||
BOOL bLogged = FALSE;
|
||||
BOOL bInit = TRUE;
|
||||
|
||||
zName = utf8ToUnicode(zFilename);
|
||||
if( zName==0 ){
|
||||
/* out of memory */
|
||||
return FALSE;
|
||||
return SQLITE_IOERR_NOMEM;
|
||||
}
|
||||
|
||||
/* Initialize the local lockdata */
|
||||
@ -1695,9 +1697,10 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
|
||||
pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
|
||||
if (!pFile->hMutex){
|
||||
pFile->lastErrno = osGetLastError();
|
||||
winLogError(SQLITE_ERROR, pFile->lastErrno, "winceCreateLock1", zFilename);
|
||||
winLogError(SQLITE_IOERR, pFile->lastErrno,
|
||||
"winceCreateLock1", zFilename);
|
||||
sqlite3_free(zName);
|
||||
return FALSE;
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
|
||||
/* Acquire the mutex before continuing */
|
||||
@ -1714,41 +1717,49 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
|
||||
|
||||
/* Set a flag that indicates we're the first to create the memory so it
|
||||
** must be zero-initialized */
|
||||
if (osGetLastError() == ERROR_ALREADY_EXISTS){
|
||||
lastErrno = osGetLastError();
|
||||
if (lastErrno == ERROR_ALREADY_EXISTS){
|
||||
bInit = FALSE;
|
||||
}
|
||||
|
||||
sqlite3_free(zName);
|
||||
|
||||
/* If we succeeded in making the shared memory handle, map it. */
|
||||
if (pFile->hShared){
|
||||
if( pFile->hShared ){
|
||||
pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared,
|
||||
FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
|
||||
/* If mapping failed, close the shared memory handle and erase it */
|
||||
if (!pFile->shared){
|
||||
if( !pFile->shared ){
|
||||
pFile->lastErrno = osGetLastError();
|
||||
winLogError(SQLITE_ERROR, pFile->lastErrno,
|
||||
"winceCreateLock2", zFilename);
|
||||
winLogError(SQLITE_IOERR, pFile->lastErrno,
|
||||
"winceCreateLock2", zFilename);
|
||||
bLogged = TRUE;
|
||||
osCloseHandle(pFile->hShared);
|
||||
pFile->hShared = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* If shared memory could not be created, then close the mutex and fail */
|
||||
if (pFile->hShared == NULL){
|
||||
if( pFile->hShared==NULL ){
|
||||
if( !bLogged ){
|
||||
pFile->lastErrno = lastErrno;
|
||||
winLogError(SQLITE_IOERR, pFile->lastErrno,
|
||||
"winceCreateLock3", zFilename);
|
||||
bLogged = TRUE;
|
||||
}
|
||||
winceMutexRelease(pFile->hMutex);
|
||||
osCloseHandle(pFile->hMutex);
|
||||
pFile->hMutex = NULL;
|
||||
return FALSE;
|
||||
return SQLITE_IOERR;
|
||||
}
|
||||
|
||||
/* Initialize the shared memory if we're supposed to */
|
||||
if (bInit) {
|
||||
if( bInit ){
|
||||
memset(pFile->shared, 0, sizeof(winceLock));
|
||||
}
|
||||
|
||||
winceMutexRelease(pFile->hMutex);
|
||||
return TRUE;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2757,7 +2768,7 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case SQLITE_FCNTL_TEMPFILENAME: {
|
||||
char *zTFile = sqlite3_malloc( pFile->pVfs->mxPathname );
|
||||
char *zTFile = sqlite3MallocZero( pFile->pVfs->mxPathname );
|
||||
if( zTFile ){
|
||||
getTempname(pFile->pVfs->mxPathname, zTFile);
|
||||
*(char**)pArg = zTFile;
|
||||
@ -3693,6 +3704,7 @@ static int winOpen(
|
||||
*/
|
||||
if( !zUtf8Name ){
|
||||
assert(isDelete && !isOpenJournal);
|
||||
memset(zTmpname, 0, MAX_PATH+2);
|
||||
rc = getTempname(MAX_PATH+2, zTmpname);
|
||||
if( rc!=SQLITE_OK ){
|
||||
return rc;
|
||||
@ -3844,11 +3856,11 @@ static int winOpen(
|
||||
|
||||
#if SQLITE_OS_WINCE
|
||||
if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
|
||||
&& !winceCreateLock(zName, pFile)
|
||||
&& (rc = winceCreateLock(zName, pFile))!=SQLITE_OK
|
||||
){
|
||||
osCloseHandle(h);
|
||||
sqlite3_free(zConverted);
|
||||
return SQLITE_CANTOPEN_BKPT;
|
||||
return rc;
|
||||
}
|
||||
if( isTemp ){
|
||||
pFile->zDeleteOnClose = zConverted;
|
||||
|
Loading…
Reference in New Issue
Block a user