1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Include the ThreadData structure in internal malloc() testing. Also fixes for revealed bugs. (CVS 2974)

FossilOrigin-Name: c7b9d50d0a975912776aaa2b870308652f77e1e6
This commit is contained in:
danielk1977
2006-01-18 18:22:43 +00:00
parent 757b04ed36
commit 76e8d1a292
10 changed files with 92 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
C Modify\sthe\ssqlite3OsInMutex\sos-layer\sinterface\sto\stake\sa\ssingle\sparameter\nto\sdistinguish\sbetween\smutexes\sheld\sby\sthe\scurrent\sthread\sand\smutexes\sheld\nby\sany\sthread.\s\sPart\sof\sthe\sfix\sfor\sticket\s#1630.\s(CVS\s2973) C Include\sthe\sThreadData\sstructure\sin\sinternal\smalloc()\stesting.\sAlso\sfixes\sfor\srevealed\sbugs.\s(CVS\s2974)
D 2006-01-18T17:25:46 D 2006-01-18T18:22:43
F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967 F Makefile.in ab3ffd8d469cef4477257169b82810030a6bb967
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -55,25 +55,25 @@ F src/os.h e4637eadcd5a9ca079029078d31751ae295fb05e
F src/os_common.h 95b29ca6f3e6636cb33c9219b3f91a96fa7224b1 F src/os_common.h 95b29ca6f3e6636cb33c9219b3f91a96fa7224b1
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c 9d44bcfbc1e0997331acec827027637dbe9d7131 F src/os_unix.c a242a9458b08f01fa11d42b23bcdb89a3fbf2a68
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c 98e4e38db7d4a00647b2bb1c60d28b7ca5034c03 F src/os_win.c 98e4e38db7d4a00647b2bb1c60d28b7ca5034c03
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 651fda1756c2334009e14bfdc652aadbdbed4e8c F src/pager.c ccdd092702decc02fd3a54380c6d46c546eea5a6
F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f F src/pager.h e0acb095b3ad0bca48f2ab00c87346665643f64f
F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c F src/parse.y 83df51fea35f68f7e07384d75dce83d1ed30434c
F src/pragma.c 4496cc77dc35824e1c978c3d1413b8a5a4c777d3 F src/pragma.c 4496cc77dc35824e1c978c3d1413b8a5a4c777d3
F src/prepare.c 5aa661a35a18edd2e13f5c87263080781cf0fcf3 F src/prepare.c 5d6f5b7194ee72cecd66cab49d15159e55d63f28
F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812 F src/printf.c f47a2f4b5387cd2ebb12e9117a1a5d6bd9a2b812
F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261 F src/random.c d40f8d356cecbd351ccfab6eaedd7ec1b54f5261
F src/select.c e80ac3438d64bfdb1116660309f578eb1efed6e1 F src/select.c e80ac3438d64bfdb1116660309f578eb1efed6e1
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
F src/sqlite.h.in 492580f7e3ff71eb43193eb7bb98e2d549889ce3 F src/sqlite.h.in 492580f7e3ff71eb43193eb7bb98e2d549889ce3
F src/sqliteInt.h ecb38c65affb3411fbd375fb14707000aab15aed F src/sqliteInt.h 7ddd6141a57748363fe42119f165d06260996aa3
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316 F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c d650bea0248fc0a310ddc2cb94273a3a5021fddf F src/tclsqlite.c d650bea0248fc0a310ddc2cb94273a3a5021fddf
F src/test1.c 2ddf346a75069254ce24853fe970f8ee2812a371 F src/test1.c 1c08d6533843687266d0d090d2c19bb0c9a9a907
F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b F src/test2.c ca74a1d8aeb7d9606e8f6b762c5daf85c1a3f92b
F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054 F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054
F src/test4.c 6633cb7b4a7429e938804a34f688d118c8b7f8e1 F src/test4.c 6633cb7b4a7429e938804a34f688d118c8b7f8e1
@@ -85,12 +85,12 @@ F src/tokenize.c 1ac078540c2074568e16c0e9beea836fb16b1adc
F src/trigger.c 4d3644cbd16959b568c95ae73493402be8021b08 F src/trigger.c 4d3644cbd16959b568c95ae73493402be8021b08
F src/update.c 14be4ba2f438919b4217085c02feff569e6cf1f2 F src/update.c 14be4ba2f438919b4217085c02feff569e6cf1f2
F src/utf.c 5ab8ca05d4e9ec81174b010f01ab12a232f0087d F src/utf.c 5ab8ca05d4e9ec81174b010f01ab12a232f0087d
F src/util.c b916d21774e6259d86e875df399dbe1a28e69b8e F src/util.c 3f09c6ffb1d0ea4efe17304c8c5c3612c5cd53fc
F src/vacuum.c 3865673cc66acd0717ecd517f6b8fdb2a5e7924b F src/vacuum.c 3865673cc66acd0717ecd517f6b8fdb2a5e7924b
F src/vdbe.c 5af32281e96b2c3e29f50975a86b9f5eef044057 F src/vdbe.c 2a3d5ea76ab166bd77de9e3a7dbeb4a9354a1603
F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13 F src/vdbe.h 8729a4ee16ff9aeab2af9667df3cf300ff978e13
F src/vdbeInt.h 5451cf71f229e366ac543607c0a17f36e5737ea9 F src/vdbeInt.h 5451cf71f229e366ac543607c0a17f36e5737ea9
F src/vdbeapi.c 08578a1d601bded62e829bc2f85281556f787333 F src/vdbeapi.c b5a3eacce266a657cdc0fc740b60ba480fb88649
F src/vdbeaux.c 1b3fe25f69ec9a3616f8cd747f3b8b87a0a40f04 F src/vdbeaux.c 1b3fe25f69ec9a3616f8cd747f3b8b87a0a40f04
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c 53f25c5c537e4ded24549d6c8537e65d4efc42d1 F src/vdbemem.c 53f25c5c537e4ded24549d6c8537e65d4efc42d1
@@ -341,7 +341,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P ac090f2ab3b5a792c2fdf897e10060f263e0d408 P e1ad9df1cf46287f2a7789275e98d28e05880e17
R 789c880886342b50e95c468de56aedb9 R d16f70b255799a1d6293d5f839dfd544
U drh U danielk1977
Z cf39b9ccff84563836ed01af4518e925 Z d52ffd289093139bee40bd2d96a45c60

View File

@@ -1 +1 @@
e1ad9df1cf46287f2a7789275e98d28e05880e17 c7b9d50d0a975912776aaa2b870308652f77e1e6

View File

@@ -1782,7 +1782,12 @@ ThreadData *sqlite3UnixThreadSpecificData(int allocateFlag){
pTsd = pthread_getspecific(key); pTsd = pthread_getspecific(key);
if( allocateFlag>0 ){ if( allocateFlag>0 ){
if( pTsd==0 ){ if( pTsd==0 ){
if( !sqlite3TestMallocFail() ){
pTsd = sqlite3OsMalloc(sizeof(zeroData)); pTsd = sqlite3OsMalloc(sizeof(zeroData));
}
#ifdef SQLITE_MEMDEBUG
sqlite3_isFail = 0;
#endif
if( pTsd ){ if( pTsd ){
*pTsd = zeroData; *pTsd = zeroData;
pthread_setspecific(key, pTsd); pthread_setspecific(key, pTsd);
@@ -1801,7 +1806,12 @@ ThreadData *sqlite3UnixThreadSpecificData(int allocateFlag){
static ThreadData *pTsd = 0; static ThreadData *pTsd = 0;
if( allocateFlag>0 ){ if( allocateFlag>0 ){
if( pTsd==0 ){ if( pTsd==0 ){
if( !sqlite3TestMallocFail() ){
pTsd = sqlite3OsMalloc( sizeof(zeroData) ); pTsd = sqlite3OsMalloc( sizeof(zeroData) );
}
#ifdef SQLITE_MEMDEBUG
sqlite3_isFail = 0;
#endif
if( pTsd ){ if( pTsd ){
*pTsd = zeroData; *pTsd = zeroData;
TSD_COUNTER(+1); TSD_COUNTER(+1);

View File

@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while ** file simultaneously, or one process from reading the database while
** another is writing. ** another is writing.
** **
** @(#) $Id: pager.c,v 1.244 2006/01/18 17:25:46 drh Exp $ ** @(#) $Id: pager.c,v 1.245 2006/01/18 18:22:43 danielk1977 Exp $
*/ */
#ifndef SQLITE_OMIT_DISKIO #ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h" #include "sqliteInt.h"
@@ -1999,6 +1999,7 @@ int sqlite3pager_close(Pager *pPager){
** so that ThreadData.nAlloc can be set. ** so that ThreadData.nAlloc can be set.
*/ */
ThreadData *pTsd = sqlite3ThreadData(); ThreadData *pTsd = sqlite3ThreadData();
assert( pPager );
assert( pTsd && pTsd->nAlloc ); assert( pTsd && pTsd->nAlloc );
#endif #endif

View File

@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema ** interface, and routines that contribute to loading the database schema
** from disk. ** from disk.
** **
** $Id: prepare.c,v 1.26 2006/01/18 16:51:35 danielk1977 Exp $ ** $Id: prepare.c,v 1.27 2006/01/18 18:22:43 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@@ -520,6 +520,9 @@ int sqlite3_prepare(
memset(&sParse, 0, sizeof(sParse)); memset(&sParse, 0, sizeof(sParse));
sParse.db = db; sParse.db = db;
sParse.pTsd = sqlite3ThreadData(); sParse.pTsd = sqlite3ThreadData();
if( !sParse.pTsd ){
goto prepare_out;
}
sParse.pTsd->nRef++; sParse.pTsd->nRef++;
sqlite3RunParser(&sParse, zSql, &zErrMsg); sqlite3RunParser(&sParse, zSql, &zErrMsg);
@@ -554,6 +557,7 @@ int sqlite3_prepare(
} }
#endif #endif
prepare_out:
if( sqlite3SafetyOff(db) ){ if( sqlite3SafetyOff(db) ){
rc = SQLITE_MISUSE; rc = SQLITE_MISUSE;
} }
@@ -570,7 +574,9 @@ int sqlite3_prepare(
sqlite3Error(db, rc, 0); sqlite3Error(db, rc, 0);
} }
if( sParse.pTsd ){
sParse.pTsd->nRef--; sParse.pTsd->nRef--;
}
rc = sqlite3ApiExit(db, rc); rc = sqlite3ApiExit(db, rc);
sqlite3ReleaseThreadData(); sqlite3ReleaseThreadData();
return rc; return rc;

View File

@@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** Internal interface definitions for SQLite. ** Internal interface definitions for SQLite.
** **
** @(#) $Id: sqliteInt.h,v 1.474 2006/01/18 16:51:35 danielk1977 Exp $ ** @(#) $Id: sqliteInt.h,v 1.475 2006/01/18 18:22:43 danielk1977 Exp $
*/ */
#ifndef _SQLITEINT_H_ #ifndef _SQLITEINT_H_
#define _SQLITEINT_H_ #define _SQLITEINT_H_
@@ -1759,7 +1759,9 @@ void sqlite3FailedMalloc();
#ifdef SQLITE_MEMDEBUG #ifdef SQLITE_MEMDEBUG
void sqlite3MallocDisallow(); void sqlite3MallocDisallow();
void sqlite3MallocAllow(); void sqlite3MallocAllow();
int sqlite3TestMallocFail();
#else #else
#define sqlite3TestMallocFail() 0
#define sqlite3MallocDisallow() #define sqlite3MallocDisallow()
#define sqlite3MallocAllow() #define sqlite3MallocAllow()
#endif #endif

View File

@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test1.c,v 1.196 2006/01/18 16:51:35 danielk1977 Exp $ ** $Id: test1.c,v 1.197 2006/01/18 18:22:43 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "tcl.h" #include "tcl.h"
@@ -911,7 +911,7 @@ static int sqlite_malloc_outstanding(
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
if( objc==2 ){ if( objc==2 ){
ThreadData *pTd = sqlite3ThreadData(); ThreadData const *pTd = sqlite3ThreadDataReadOnly();
const char *zArg = Tcl_GetString(objv[1]); const char *zArg = Tcl_GetString(objv[1]);
if( 0==strcmp(zArg, "-bytes") ){ if( 0==strcmp(zArg, "-bytes") ){
Tcl_SetObjResult(interp, Tcl_NewIntObj(pTd->nAlloc)); Tcl_SetObjResult(interp, Tcl_NewIntObj(pTd->nAlloc));

View File

@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing ** This file contains functions for allocating memory, comparing
** strings, and stuff like that. ** strings, and stuff like that.
** **
** $Id: util.c,v 1.177 2006/01/18 17:25:46 drh Exp $ ** $Id: util.c,v 1.178 2006/01/18 18:22:43 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@@ -72,7 +72,10 @@
** value indicates no limit. ** value indicates no limit.
*/ */
void sqlite3_soft_heap_limit(int n){ void sqlite3_soft_heap_limit(int n){
sqlite3ThreadData()->nSoftHeapLimit = n; ThreadData *pTd = sqlite3ThreadData();
if( pTd ){
pTd->nSoftHeapLimit = n;
}
sqlite3ReleaseThreadData(); sqlite3ReleaseThreadData();
} }
@@ -207,8 +210,7 @@ int sqlite3_iLine = 0; /* Line number for debug info */
** Check for a simulated memory allocation failure. Return true if ** Check for a simulated memory allocation failure. Return true if
** the failure should be simulated. Return false to proceed as normal. ** the failure should be simulated. Return false to proceed as normal.
*/ */
static int failMalloc(){ int sqlite3TestMallocFail(){
ThreadData *pTsd = sqlite3ThreadData();
if( sqlite3_isFail ){ if( sqlite3_isFail ){
return 1; return 1;
} }
@@ -316,7 +318,6 @@ static void *getOsPointer(void *p)
** of allocations. ** of allocations.
*/ */
static void linkAlloc(void *p){ static void linkAlloc(void *p){
ThreadData *pTsd = sqlite3ThreadData();
void **pp = (void **)p; void **pp = (void **)p;
pp[0] = 0; pp[0] = 0;
pp[1] = sqlite3_pFirst; pp[1] = sqlite3_pFirst;
@@ -332,7 +333,6 @@ static void linkAlloc(void *p){
*/ */
static void unlinkAlloc(void *p) static void unlinkAlloc(void *p)
{ {
ThreadData *pTsd = sqlite3ThreadData();
void **pp = (void **)p; void **pp = (void **)p;
if( p==sqlite3_pFirst ){ if( p==sqlite3_pFirst ){
assert(!pp[0]); assert(!pp[0]);
@@ -365,7 +365,6 @@ static void relinkAlloc(void *p)
if( pp[0] ){ if( pp[0] ){
((void **)(pp[0]))[1] = p; ((void **)(pp[0]))[1] = p;
}else{ }else{
ThreadData *pTsd = sqlite3ThreadData();
sqlite3_pFirst = p; sqlite3_pFirst = p;
} }
if( pp[1] ){ if( pp[1] ){
@@ -397,7 +396,6 @@ static void relinkAlloc(void *p)
#include <tcl.h> #include <tcl.h>
int sqlite3OutstandingMallocs(Tcl_Interp *interp){ int sqlite3OutstandingMallocs(Tcl_Interp *interp){
void *p; void *p;
ThreadData *pTsd = sqlite3ThreadData();
Tcl_Obj *pRes = Tcl_NewObj(); Tcl_Obj *pRes = Tcl_NewObj();
Tcl_IncrRefCount(pRes); Tcl_IncrRefCount(pRes);
@@ -445,11 +443,11 @@ int sqlite3OutstandingMallocs(Tcl_Interp *interp){
*/ */
static void * OSMALLOC(int n){ static void * OSMALLOC(int n){
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
ThreadData *pTsd = sqlite3ThreadData(); ThreadData const *pTsd = sqlite3ThreadDataReadOnly();
sqlite3_nMaxAlloc = MAX(sqlite3_nMaxAlloc, pTsd->nAlloc); sqlite3_nMaxAlloc = MAX(sqlite3_nMaxAlloc, pTsd->nAlloc);
#endif #endif
assert( !sqlite3_mallocDisallowed ); assert( !sqlite3_mallocDisallowed );
if( !failMalloc() ){ if( !sqlite3TestMallocFail() ){
u32 *p; u32 *p;
p = (u32 *)sqlite3OsMalloc(n + TESTALLOC_OVERHEAD); p = (u32 *)sqlite3OsMalloc(n + TESTALLOC_OVERHEAD);
assert(p); assert(p);
@@ -488,10 +486,13 @@ static void OSFREE(void *pFree){
static void * OSREALLOC(void *pRealloc, int n){ static void * OSREALLOC(void *pRealloc, int n){
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
ThreadData *pTsd = sqlite3ThreadData(); ThreadData *pTsd = sqlite3ThreadData();
if( !pTsd ){
return 0;
}
sqlite3_nMaxAlloc = MAX(sqlite3_nMaxAlloc, pTsd->nAlloc); sqlite3_nMaxAlloc = MAX(sqlite3_nMaxAlloc, pTsd->nAlloc);
#endif #endif
assert( !sqlite3_mallocDisallowed ); assert( !sqlite3_mallocDisallowed );
if( !failMalloc() ){ if( !sqlite3TestMallocFail() ){
u32 *p = (u32 *)getOsPointer(pRealloc); u32 *p = (u32 *)getOsPointer(pRealloc);
checkGuards(p); checkGuards(p);
p = sqlite3OsRealloc(p, n + TESTALLOC_OVERHEAD); p = sqlite3OsRealloc(p, n + TESTALLOC_OVERHEAD);
@@ -535,8 +536,9 @@ static void OSMALLOC_FAILED(){
** a no-op ** a no-op
*/ */
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
static void handleSoftLimit(int n){ static int handleSoftLimit(int n){
ThreadData *pTsd = sqlite3ThreadData(); ThreadData *pTsd = sqlite3ThreadData();
if( pTsd ){
pTsd->nAlloc += n; pTsd->nAlloc += n;
assert( pTsd->nAlloc>=0 ); assert( pTsd->nAlloc>=0 );
if( n>0 && pTsd->nSoftHeapLimit>0 ){ if( n>0 && pTsd->nSoftHeapLimit>0 ){
@@ -544,9 +546,11 @@ static void handleSoftLimit(int n){
}else if( pTsd->nAlloc==0 && pTsd->nSoftHeapLimit==0 ){ }else if( pTsd->nAlloc==0 && pTsd->nSoftHeapLimit==0 ){
sqlite3ReleaseThreadData(); sqlite3ReleaseThreadData();
} }
}
return (pTsd ? 0 : 1);
} }
#else #else
#define handleSoftLimit(x) #define handleSoftLimit(x) 0
#endif #endif
/* /*
@@ -556,8 +560,7 @@ static void handleSoftLimit(int n){
*/ */
void *sqlite3MallocRaw(int n){ void *sqlite3MallocRaw(int n){
void *p = 0; void *p = 0;
if( n>0 && !sqlite3MallocFailed() ){ if( n>0 && !sqlite3MallocFailed() && !handleSoftLimit(n) ){
handleSoftLimit(n);
while( !(p = OSMALLOC(n)) && sqlite3_release_memory(n) ); while( !(p = OSMALLOC(n)) && sqlite3_release_memory(n) );
if( !p ){ if( !p ){
/* If the allocation failed, call handleSoftLimit() again, this time /* If the allocation failed, call handleSoftLimit() again, this time
@@ -587,7 +590,7 @@ void *sqlite3Realloc(void *p, int n){
return sqlite3Malloc(n); return sqlite3Malloc(n);
}else{ }else{
void *np = 0; void *np = 0;
handleSoftLimit(n - OSSIZEOF(p)); if( !handleSoftLimit(n - OSSIZEOF(p)) ){
while( !(np = OSREALLOC(p, n)) && sqlite3_release_memory(n) ); while( !(np = OSREALLOC(p, n)) && sqlite3_release_memory(n) );
if( !np ){ if( !np ){
/* If the allocation failed, call handleSoftLimit() again, this time /* If the allocation failed, call handleSoftLimit() again, this time
@@ -599,6 +602,7 @@ void *sqlite3Realloc(void *p, int n){
sqlite3FailedMalloc(); sqlite3FailedMalloc();
OSMALLOC_FAILED(); OSMALLOC_FAILED();
} }
}
return np; return np;
} }
} }
@@ -1322,7 +1326,11 @@ void *sqlite3TextToPtr(const char *z){
** Return a pointer to the ThreadData associated with the calling thread. ** Return a pointer to the ThreadData associated with the calling thread.
*/ */
ThreadData *sqlite3ThreadData(){ ThreadData *sqlite3ThreadData(){
return (ThreadData*)sqlite3OsThreadSpecificData(1); ThreadData *p = (ThreadData*)sqlite3OsThreadSpecificData(1);
if( !p ){
sqlite3FailedMalloc();
}
return p;
} }
/* /*

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.532 2006/01/18 16:51:36 danielk1977 Exp $ ** $Id: vdbe.c,v 1.533 2006/01/18 18:22:43 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@@ -408,6 +408,9 @@ int sqlite3VdbeExec(
Mem *pStackLimit; Mem *pStackLimit;
#endif #endif
ThreadData *pTsd = sqlite3ThreadData(); ThreadData *pTsd = sqlite3ThreadData();
if( !pTsd ){
goto no_mem;
}
if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE; if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE;
pTsd->nRef++; pTsd->nRef++;
@@ -4615,7 +4618,9 @@ vdbe_halt:
} }
sqlite3VdbeHalt(p); sqlite3VdbeHalt(p);
p->pTos = pTos; p->pTos = pTos;
if( pTsd ){
pTsd->nRef--; pTsd->nRef--;
}
return rc; return rc;
/* Jump to here if a malloc() fails. It's hard to get a malloc() /* Jump to here if a malloc() fails. It's hard to get a malloc()

View File

@@ -242,7 +242,8 @@ int sqlite3_step(sqlite3_stmt *pStmt){
#endif #endif
sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg); sqlite3Error(p->db, rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
return sqlite3ApiExit(p->db, rc); p->rc = sqlite3ApiExit(p->db, p->rc);
return rc;
} }
/* /*