The malloc.test script now passes all tests with no errors. (CVS 4271)

FossilOrigin-Name: db818430e9ea4ef4a4af575784009d5acae785a3
This commit is contained in:
drh 2007-08-22 20:18:21 +00:00
parent dd97a49c1a
commit f3a65f7e44
25 changed files with 192 additions and 153 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sbug\sin\sthe\slogic\sfor\sjournaling\spages\swhen\sthe\sdevice\ssector-size\sis\sgreater\sthan\sthe\spage\ssize.\s(CVS\s4270)
D 2007-08-22T18:54:33
C The\smalloc.test\sscript\snow\spasses\sall\stests\swith\sno\serrors.\s(CVS\s4271)
D 2007-08-22T20:18:22
F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -83,26 +83,26 @@ F src/auth.c 083c1205b45e3f52291ec539d396b4fc557856b3
F src/btree.c 1e189c3a7ea8e34434b214a8d6b69727c3ed525c
F src/btree.h 76c89673981cb77575300c0b78a76eaa00a28743
F src/btreeInt.h 7fc6e51dc3d4bbed15639a8ea1aae737631d6670
F src/build.c 2159551184160e2cf17ff945e9a05fbe6f331c3d
F src/callback.c fdd527372162a974094103eae82119fcfcf11260
F src/build.c bc7406e2ea5bfa8276ee1abeae1db27a98fd0b33
F src/callback.c a542236a68060caad378efa30006ca46cf77b1b2
F src/complete.c b6dea59fb6d7b3201fa1e0e552cda8c2258a4f50
F src/date.c a80b33f6e70d619978622547d2c78ab8b036b31a
F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 3ea108a9e409f58b8203e29c54442da5085be5bf
F src/expr.c 978afdceb2693ef58ec0040a43fe57afc6e4236c
F src/func.c 36440cb02589fd4697cbbf0b351eeedc160d1f4b
F src/hash.c 2f322979071dd2bdba7503b5276d66f028744382
F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e
F src/insert.c 633322aef1799f6604fa805e12488bc628570b0c
F src/journal.c 5ba2a1443b181741d3f2984d9d49e730073d74d1
F src/legacy.c a83519a8fbb488c3155fca577b010d590ec479e9
F src/legacy.c 7e1b1c57694e49cbadf561e2a7d9cd984dc743b5
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c dd803303fd06ef0b13913faaa4a7fc7d8c8c4e77
F src/main.c ea11ee57f35ba85feb3c1f8ca81ac9caad718be2
F src/malloc.c f5ace943194fba04f09b590496a751a5ed6734f1
F src/main.c 527f27c74d22d83713abbd1550fd5a4ecce89aca
F src/malloc.c 8078d4c3f9217c0bb018e432d8655c14996bb107
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 30bf8be3846f92fdf88c490c5e5378512383bcbe
F src/mem2.c 482f0aaf14e8ef1db64cb8c5b9a9bfe708297c92
F src/mem1.c 7b023d45dd71944414db469c742457239e24d74d
F src/mem2.c b707e02fec2cf4d6fce8427d640e90d5003afe9e
F src/mutex.c 9cf641f556a4119ef90ed41b82f2d5647f81686e
F src/os.c d8f029317c95dcd2887b9f0f154281cdfbd303ad
F src/os.h 399c89cafa93b9ef35c3dc70f77644d10936b535
@ -111,7 +111,7 @@ F src/os_os2.c 8769301bff502de642ad2634cedcb77d967ce199
F src/os_os2.h c3f7d0af7e3453d1d7aa81b06c0a56f5a226530b
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c 7aad42b1ee70d68034a4ac45fa822edccdc3d9e6
F src/os_unix.c 3e1ce27aa8364f92881a285820ffa414539a6b1b
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c 29c0e19c1072679a4c7818c49fab2f35d2ad7747
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
@ -120,18 +120,18 @@ F src/pager.h 53087c6fb9db01aed17c7fd044662a27507e89b8
F src/parse.y 2d2ce439dc6184621fb0b86f4fc5aca7f391a590
F src/pragma.c 9b989506a1b7c8aecd6befb8235e2f57a4aba7e5
F src/prepare.c 29ea14cf6b0558f2f80aa53e112bff55f1119e36
F src/printf.c a8f46e0ed360c18d40e89aa636533be300b406c2
F src/printf.c 0f46bc3a805d5620f5aedfec1c3768d293a5ee5e
F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da
F src/select.c 98c367bce3f38c5adfcc97de9ab5c79b0e5dc2b2
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb
F src/sqlite.h.in 39f920631c49a8a79502d8b7908e608d7a0029bd
F src/sqlite3ext.h 647a6b8a8f76ff6c9611e4a071531d8e63ff2d6b
F src/sqlite.h.in ab5c1bde4c253efabbd815c9df796656a95f16d3
F src/sqlite3ext.h 9a26028378c288af500d8b94ed079666fed5806b
F src/sqliteInt.h 67b6ed04a2b0c28957bc2cf064ce713d298022b3
F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa
F src/table.c c725e47f6f3092b9a7b569fc58e408e2173ee008
F src/tclsqlite.c 92e06e076d613484aa2afc5ad830d9080de92347
F src/test1.c d7b8d6d15d10cc2e21f7a20a09c914d5aa84f1e2
F src/tclsqlite.c d76af53f45c9e9f7f7d39531fa4c7bee7d0adad6
F src/test1.c 95a5db021760d074d5028dd16366aca289a441bf
F src/test2.c 4f742e99ed1bea5c14692f627bdb59a146f30504
F src/test3.c a7d011c51d6b2e2a73c43983d5c2b731d69c74d7
F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071
@ -143,16 +143,16 @@ F src/test9.c b46c8fe02ac7cca1a7316436d8d38d50c66f4b2f
F src/test_async.c 9f3ab66e848930d1c3a7bc2dde77b9b643f6e4ba
F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c
F src/test_config.c 6c74d82fd4a0a5a3bebd53a9cb2cb6c02af68e07
F src/test_config.c f0b911bb615d93a192647e76910dce65cbbcf3ad
F src/test_hexio.c 82916f918687502658f02533b519c38cb180db6d
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c d9ba6be85f9c4a439b19f6e0a72d91c369d72c63
F src/test_md5.c d9f828765b242ff86f58cd879259c3da4eaede02
F src/test_md5.c 34599caee5b1c73dcf86ca31f55846fab8c19ef7
F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f
F src/test_server.c 319f6b1a99bab5f7149387442243d6e65a8ab4eb
F src/test_tclvar.c b2d1115e4d489179d3f029e765211b2ad527ba59
F src/tokenize.c e39527c9c867774a92716c669a48ad8fbc3cdc63
F src/trigger.c dccc6fbf37d12193c90ede5b026bbd195d505ff4
F src/tokenize.c fda6edc179c16351dc7fd05f8ea08e427361522c
F src/trigger.c 724a77d54609a33bde90618934fbeddfcc729a10
F src/update.c e89b980b443d44b68bfc0b1746cdb6308e049ac9
F src/utf.c 4af6259d5906b5a1bf3035cc387c4d7907bdd56e
F src/util.c 3f9c0387b54f977726790f52ab92cd3d9379b367
@ -164,7 +164,7 @@ F src/vdbeapi.c 81cb7f018e56c20b40365f005ff69e1af9ea9494
F src/vdbeaux.c b0aeed4ff33352904b392ee6c7408bae5b141b9b
F src/vdbeblob.c d12ed95dac0992e1e372d079d76af047cc42f7c7
F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
F src/vdbemem.c 3de25d78e7b1d0af7a05199de905cea8c43aed5d
F src/vdbemem.c 896fa3f8df9d2661eb15c7ce361857741b447268
F src/vtab.c 8f80924af48fc2295d36f6fe360d3c99ae968f9d
F src/where.c 2776a0caf8cbbfd6ec79cfb1cd9bc25074055e5e
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@ -338,7 +338,7 @@ F test/lock2.test 5f9557b775662c2a5ee435378f39e10d64f65cb3
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
F test/lock4.test 49e22396b9be6e047b3d35469f233be79153c9d5
F test/main.test e7212ce1023957c7209778cc87fa932bd79ba89a
F test/malloc.test 42e71334eba7e311674625340d464db57d47788e
F test/malloc.test dbfaedfca734283182db18a64416cf037c33648f
F test/malloc2.test 4ed7d719542c4570dec9c2ebe2bbdf3a9f3b0d05
F test/malloc3.test e965954b6f808876a63d3101fd70370320b509a7
F test/malloc4.test 59cd02f71b363302a04c4e77b97c0a1572eaa210
@ -350,7 +350,7 @@ F test/malloc9.test 8381041fd89c31fba60c8a1a1c776bb022108572
F test/mallocA.test 525674e6e0775a9bf85a33f1da1c6bbddc712c30
F test/mallocB.test 5d4a3dc4931a8c13ef3723c4934af23ff9d60d71
F test/mallocC.test e470e03fe8b28d79f0a5123601a9653331cc7226
F test/malloc_common.tcl 3cda97d63fbf370061ffa9795a24e5027367fef3
F test/malloc_common.tcl 7b59db5f0617678f4e5af3a7b3715a1dacd1b8e2
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
@ -362,7 +362,7 @@ F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
F test/misc4.test 21e8a275cadcf2ba2a9ac2c33ae024ecc5eaff3a
F test/misc5.test c7d2d2a5a20dc37d3605a8067f0df5af2240122e
F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91
F test/misc7.test 6e573e3d635ac539ba480630f68b2fbe32d19d82
F test/misc7.test a67af9620a510ce19f96ba69f3848228b7c62a73
F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33
F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82
F test/null.test 9503e1f63e959544c006d9f01709c5b5eab67d54
@ -412,7 +412,7 @@ F test/table.test dbdfd06aef054ad5aed8e57a782137d57d5c5528
F test/tableapi.test 036575a98dcce7c92e9f39056839bbad8a715412
F test/tclsqlite.test 593f3b30221e85786965d9e5670ae4f96b4e4159
F test/temptable.test c36f3e5a94507abb64f7ba23deeb4e1a8a8c3821
F test/tester.tcl 7907d791de322547e496a28b50de41b564d3a5fc
F test/tester.tcl e72b0b8e1b1d9cf20bc641793a3d3c5442a5bbb3
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
F test/thread2.test 6d7b30102d600f51b4055ee3a5a19228799049fb
F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
@ -559,7 +559,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 1f28b7e47bba221c14a10a37e7425c9975bb2312
R cf0de8a627c4e3c426ffb917c87f2598
U danielk1977
Z fbf5424b267fecb1d05194b85e3145a4
P b6399dff1370449912391cc5925bdc468b5dade0
R 3ea0ebd7e3bb257a718fe4ade9660d28
U drh
Z 59e51dd8c4f548815477ba78b815fe4b

View File

@ -1 +1 @@
b6399dff1370449912391cc5925bdc468b5dade0
db818430e9ea4ef4a4af575784009d5acae785a3

View File

@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.437 2007/08/21 19:33:56 drh Exp $
** $Id: build.c,v 1.438 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -90,6 +90,9 @@ void sqlite3TableLock(
p->iTab = iTab;
p->isWriteLock = isWriteLock;
p->zName = zName;
}else{
pParse->nTableLock = 0;
pParse->db->mallocFailed = 1;
}
}

View File

@ -13,7 +13,7 @@
** This file contains functions used to access the internal hash tables
** of user defined functions and collation sequences.
**
** $Id: callback.c,v 1.21 2007/08/21 19:33:56 drh Exp $
** $Id: callback.c,v 1.22 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
@ -179,8 +179,9 @@ static CollSeq *findCollSeqEntry(
** return the pColl pointer to be deleted (because it wasn't added
** to the hash table).
*/
assert( !pDel || (db->mallocFailed && pDel==pColl) );
if( pDel ){
assert( pDel==0 || pDel==pColl );
if( pDel!=0 ){
db->mallocFailed = 1;
sqlite3_free(pDel);
pColl = 0;
}
@ -310,6 +311,7 @@ FuncDef *sqlite3FindFunction(
memcpy(pBest->zName, zName, nName);
pBest->zName[nName] = 0;
if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
db->mallocFailed = 1;
sqlite3_free(pBest);
return 0;
}

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.307 2007/08/16 12:24:02 drh Exp $
** $Id: expr.c,v 1.308 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -275,8 +275,6 @@ Expr *sqlite3PExpr(
){
Expr *pNew = sqlite3Expr(op, pLeft, pRight, pToken);
if( pNew==0 ){
sqlite3ExprDelete(pLeft);
sqlite3ExprDelete(pRight);
pParse->db->mallocFailed = 1;
}
return pNew;
@ -339,7 +337,7 @@ Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
assert( pRight!=0 );
assert( pLeft!=0 );
if( pRight->z && pLeft->z ){
if( pExpr && pRight->z && pLeft->z ){
assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 );
if( pLeft->dyn==0 && pRight->dyn==0 ){
pExpr->span.z = pLeft->z;

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: legacy.c,v 1.20 2007/08/21 10:44:16 drh Exp $
** $Id: legacy.c,v 1.21 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
@ -115,7 +115,7 @@ exec_out:
if( pStmt ) sqlite3_finalize(pStmt);
if( azCols ) sqlite3_free(azCols);
rc = sqlite3ApiExit(0, rc);
rc = sqlite3ApiExit(db, rc);
if( rc!=SQLITE_OK && rc==sqlite3_errcode(db) && pzErrMsg ){
int nErrMsg = 1 + strlen(sqlite3_errmsg(db));
*pzErrMsg = sqlite3_malloc(nErrMsg);

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.395 2007/08/22 02:56:44 drh Exp $
** $Id: main.c,v 1.396 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -1076,7 +1076,9 @@ static int openDatabase(
#endif
opendb_out:
sqlite3_mutex_leave(db->mutex);
if( db ){
sqlite3_mutex_leave(db->mutex);
}
if( SQLITE_NOMEM==(rc = sqlite3_errcode(db)) ){
sqlite3_close(db);
db = 0;

View File

@ -12,7 +12,7 @@
** Memory allocation functions used throughout sqlite.
**
**
** $Id: malloc.c,v 1.9 2007/08/22 00:39:20 drh Exp $
** $Id: malloc.c,v 1.10 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@ -97,7 +97,7 @@ void *sqlite3DbMallocZero(sqlite3 *db, unsigned n){
*/
void *sqlite3DbMallocRaw(sqlite3 *db, unsigned n){
void *p = sqlite3_malloc(n);
if( !p ){
if( !p && db ){
db->mallocFailed = 1;
}
return p;

View File

@ -12,7 +12,7 @@
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** $Id: mem1.c,v 1.6 2007/08/17 15:53:36 danielk1977 Exp $
** $Id: mem1.c,v 1.7 2007/08/22 20:18:22 drh Exp $
*/
/*
@ -148,8 +148,11 @@ static void sqlite3MemsysAlarm(unsigned nByte){
/*
** Allocate nBytes of memory
*/
void *sqlite3_malloc(unsigned int nBytes){
void *sqlite3_malloc(int nBytes){
sqlite3_uint64 *p;
if( nBytes<=0 ){
return 0;
}
if( mem.mutex==0 ){
mem.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM);
}
@ -196,13 +199,13 @@ void sqlite3_free(void *pPrior){
/*
** Change the size of an existing memory allocation
*/
void *sqlite3_realloc(void *pPrior, unsigned int nBytes){
void *sqlite3_realloc(void *pPrior, int nBytes){
unsigned nOld;
sqlite3_uint64 *p;
if( pPrior==0 ){
return sqlite3_malloc(nBytes);
}
if( nBytes==0 ){
if( nBytes<=0 ){
sqlite3_free(pPrior);
return 0;
}

View File

@ -12,7 +12,7 @@
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** $Id: mem2.c,v 1.5 2007/08/20 22:48:43 drh Exp $
** $Id: mem2.c,v 1.6 2007/08/22 20:18:22 drh Exp $
*/
/*
@ -249,13 +249,16 @@ static void sqlite3MemsysFailed(void){
/*
** Allocate nByte bytes of memory.
*/
void *sqlite3_malloc(unsigned int nByte){
void *sqlite3_malloc(int nByte){
struct MemBlockHdr *pHdr;
void **pBt;
unsigned int *pInt;
void *p;
unsigned int totalSize;
if( nByte<=0 ){
return 0;
}
if( mem.mutex==0 ){
mem.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM);
}
@ -364,13 +367,13 @@ void sqlite3_free(void *pPrior){
** much more likely to break and we are much more liking to find
** the error.
*/
void *sqlite3_realloc(void *pPrior, unsigned int nByte){
void *sqlite3_realloc(void *pPrior, int nByte){
struct MemBlockHdr *pOldHdr;
void *pNew;
if( pPrior==0 ){
return sqlite3_malloc(nByte);
}
if( nByte==0 ){
if( nByte<=0 ){
sqlite3_free(pPrior);
return 0;
}
@ -430,9 +433,10 @@ void sqlite3_memdebug_dump(const char *zFilename){
** This routine is used to simulate malloc failures.
**
** After calling this routine, there will be iFail successful
** memory allocations and then a failure. If iRepeat is true,
** memory allocations and then a failure. If iRepeat is 1
** all subsequent memory allocations will fail. If iRepeat is
** false, only a single allocation will fail.
** 0, only a single allocation will fail. If iRepeat is negative
** then the previous setting for iRepeat is unchanged.
**
** Each call to this routine overrides the previous. To disable
** the simulated allocation failure mechanism, set iFail to -1.
@ -443,7 +447,9 @@ void sqlite3_memdebug_dump(const char *zFilename){
int sqlite3_memdebug_fail(int iFail, int iRepeat){
int n = mem.iFailCnt;
mem.iFail = iFail+1;
mem.iReset = iRepeat;
if( iRepeat>=0 ){
mem.iReset = iRepeat;
}
mem.iFailCnt = 0;
return n;
}

View File

@ -2317,14 +2317,10 @@ static int fillInUnixFile(
** the file descriptor *pFd using close().
*/
static int openDirectory(const char *zFilename, int *pFd){
char *zDirname;
int ii;
int fd;
char zDirname[MAX_PATHNAME+1];
zDirname = (char *)sqlite3_malloc(MAX_PATHNAME);
if( !zDirname ){
return SQLITE_NOMEM;
}
strncpy(zDirname, zFilename, MAX_PATHNAME);
zDirname[MAX_PATHNAME-1] = '\0';
for(ii=strlen(zDirname); ii>=0 && zDirname[ii]!='/'; ii--);
@ -2338,7 +2334,6 @@ static int openDirectory(const char *zFilename, int *pFd){
OSTRACE3("OPENDIR %-3d %s\n", fd, zDirname);
}
}
sqlite3_free(zDirname);
*pFd = fd;
return (fd>0?SQLITE_OK:SQLITE_CANTOPEN);
}

View File

@ -717,7 +717,7 @@ struct sgMprintf {
int nChar; /* Length of the string so far */
int nTotal; /* Output size if unconstrained */
int nAlloc; /* Amount of space allocated in zText */
void *(*xRealloc)(void*, unsigned int); /* Function used to realloc memory */
void *(*xRealloc)(void*,int); /* Function used to realloc memory */
};
/*
@ -769,7 +769,7 @@ static void mout(void *arg, const char *zNewText, int nNewChar){
** the consumer.
*/
static char *base_vprintf(
void *(*xRealloc)(void*, unsigned int), /* realloc() function. May be NULL */
void *(*xRealloc)(void*, int), /* realloc() function. May be NULL */
int useInternal, /* Use internal %-conversions if true */
char *zInitBuf, /* Initially write here, before mallocing */
int nInitBuf, /* Size of zInitBuf[] */
@ -801,7 +801,7 @@ static char *base_vprintf(
/*
** Realloc that is a real function, not a macro.
*/
static void *printf_realloc(void *old, unsigned int size){
static void *printf_realloc(void *old, int size){
return sqlite3_realloc(old, size);
}

View File

@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.236 2007/08/22 00:39:20 drh Exp $
** @(#) $Id: sqlite.h.in,v 1.237 2007/08/22 20:18:22 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@ -1070,8 +1070,8 @@ char *sqlite3_snprintf(int,char*,const char*, ...);
** SQLite. The application that links against SQLite is
** expected to provide its own implementation.
*/
void *sqlite3_malloc(unsigned int);
void *sqlite3_realloc(void*, unsigned int);
void *sqlite3_malloc(int);
void *sqlite3_realloc(void*, int);
void sqlite3_free(void*);
/*

View File

@ -15,7 +15,7 @@
** as extensions by SQLite should #include this file instead of
** sqlite3.h.
**
** @(#) $Id: sqlite3ext.h,v 1.13 2007/08/16 10:09:03 danielk1977 Exp $
** @(#) $Id: sqlite3ext.h,v 1.14 2007/08/22 20:18:22 drh Exp $
*/
#ifndef _SQLITE3EXT_H_
#define _SQLITE3EXT_H_
@ -102,7 +102,7 @@ struct sqlite3_api_routines {
sqlite_int64 (*last_insert_rowid)(sqlite3*);
const char * (*libversion)(void);
int (*libversion_number)(void);
void *(*malloc)(unsigned int);
void *(*malloc)(int);
char * (*mprintf)(const char*,...);
int (*open)(const char*,sqlite3**);
int (*open16)(const void*,sqlite3**);
@ -110,7 +110,7 @@ struct sqlite3_api_routines {
int (*prepare16)(sqlite3*,const void*,int,sqlite3_stmt**,const void**);
void * (*profile)(sqlite3*,void(*)(void*,const char*,sqlite_uint64),void*);
void (*progress_handler)(sqlite3*,int,int(*)(void*),void*);
void *(*realloc)(void*,unsigned int);
void *(*realloc)(void*,int);
int (*reset)(sqlite3_stmt*pStmt);
void (*result_blob)(sqlite3_context*,const void*,int,void(*)(void*));
void (*result_double)(sqlite3_context*,double);

View File

@ -12,7 +12,7 @@
** A TCL Interface to SQLite. Append this file to sqlite3.c and
** compile the whole thing to build a TCL-enabled version of SQLite.
**
** $Id: tclsqlite.c,v 1.197 2007/08/22 00:39:21 drh Exp $
** $Id: tclsqlite.c,v 1.198 2007/08/22 20:18:22 drh Exp $
*/
#include "tcl.h"
#include <errno.h>
@ -2350,8 +2350,20 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
sqlite3_close(p->db);
p->db = 0;
}
#ifdef SQLITE_TEST
if( p->db ){
extern int Md5_Register(sqlite3*);
if( Md5_Register(p->db)==SQLITE_NOMEM ){
zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
sqlite3_close(p->db);
p->db = 0;
}
}
#endif
#ifdef SQLITE_HAS_CODEC
sqlite3_key(p->db, pKey, nKey);
if( p->db ){
sqlite3_key(p->db, pKey, nKey);
}
#endif
if( p->db==0 ){
Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
@ -2363,23 +2375,6 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
p->interp = interp;
zArg = Tcl_GetStringFromObj(objv[1], 0);
Tcl_CreateObjCommand(interp, zArg, DbObjCmd, (char*)p, DbDeleteCmd);
/* If compiled with SQLITE_TEST turned on, then register the "md5sum"
** SQL function.
*/
#ifdef SQLITE_TEST
{
extern void Md5_Register(sqlite3*);
#if 0
int mallocfail = sqlite3_iMallocFail;
sqlite3_iMallocFail = 0;
#endif
Md5_Register(p->db);
#if 0
sqlite3_iMallocFail = mallocfail;
#endif
}
#endif
return TCL_OK;
}

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.269 2007/08/22 02:56:44 drh Exp $
** $Id: test1.c,v 1.270 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -955,12 +955,18 @@ static int test_create_function(
** because it is not tested anywhere else. */
if( rc==SQLITE_OK ){
sqlite3_value *pVal;
pVal = sqlite3ValueNew(0);
sqlite3_mutex_enter(db->mutex);
pVal = sqlite3ValueNew(db);
sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC);
rc = sqlite3_create_function16(db,
if( db->mallocFailed ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_create_function16(db,
sqlite3ValueText(pVal, SQLITE_UTF16NATIVE),
1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0);
}
sqlite3ValueFree(pVal);
sqlite3_mutex_leave(db->mutex);
}
#endif
@ -2134,12 +2140,18 @@ static int test_collate(
sqlite3_iMallocFail++;
}
#endif
pVal = sqlite3ValueNew(0);
sqlite3_mutex_enter(db->mutex);
pVal = sqlite3ValueNew(db);
sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC);
rc = sqlite3_create_collation16(db,
if( db->mallocFailed ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_create_collation16(db,
sqlite3ValueText(pVal, SQLITE_UTF16NATIVE), SQLITE_UTF16BE,
(void *)SQLITE_UTF16BE, val?test_collate_func:0);
}
sqlite3ValueFree(pVal);
sqlite3_mutex_leave(db->mutex);
}
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;

View File

@ -16,7 +16,7 @@
** The focus of this file is providing the TCL testing layer
** access to compile-time constants.
**
** $Id: test_config.c,v 1.11 2007/08/21 10:44:16 drh Exp $
** $Id: test_config.c,v 1.12 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -59,6 +59,12 @@ static void set_options(Tcl_Interp *interp){
Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_MEMDEBUG
Tcl_SetVar2(interp, "sqlite_options", "memdebug", "1", TCL_GLOBAL_ONLY);
#else
Tcl_SetVar2(interp, "sqlite_options", "memdebug", "0", TCL_GLOBAL_ONLY);
#endif
#ifdef SQLITE_OMIT_ALTERTABLE
Tcl_SetVar2(interp, "sqlite_options", "altertable", "0", TCL_GLOBAL_ONLY);
#else

View File

@ -382,7 +382,7 @@ static void md5finalize(sqlite3_context *context){
DigestToBase16(digest, zBuf);
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
}
void Md5_Register(sqlite3 *db){
sqlite3_create_function(db, "md5sum", -1, SQLITE_UTF8, 0, 0,
md5step, md5finalize);
int Md5_Register(sqlite3 *db){
return sqlite3_create_function(db, "md5sum", -1, SQLITE_UTF8, 0, 0,
md5step, md5finalize);
}

View File

@ -15,7 +15,7 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.134 2007/08/21 10:44:16 drh Exp $
** $Id: tokenize.c,v 1.135 2007/08/22 20:18:22 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -401,6 +401,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
i = 0;
pEngine = sqlite3ParserAlloc((void*(*)(size_t))sqlite3_malloc);
if( pEngine==0 ){
db->mallocFailed = 1;
return SQLITE_NOMEM;
}
assert( pParse->sLastToken.dyn==0 );

View File

@ -265,7 +265,8 @@ void sqlite3FinishTrigger(
pDel = sqlite3HashInsert(&db->aDb[iDb].pSchema->trigHash,
pTrig->name, strlen(pTrig->name), pTrig);
if( pDel ){
assert( db->mallocFailed && pDel==pTrig );
assert( pDel==pTrig );
db->mallocFailed = 1;
goto triggerfinish_cleanup;
}
n = strlen(pTrig->table) + 1;
@ -356,11 +357,12 @@ TriggerStep *sqlite3TriggerInsertStep(
Select *pSelect, /* A SELECT statement that supplies values */
int orconf /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
){
TriggerStep *pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
TriggerStep *pTriggerStep;
assert(pEList == 0 || pSelect == 0);
assert(pEList != 0 || pSelect != 0);
assert(pEList != 0 || pSelect != 0 || db->mallocFailed);
pTriggerStep = sqlite3DbMallocZero(db, sizeof(TriggerStep));
if( pTriggerStep ){
pTriggerStep->op = TK_INSERT;
pTriggerStep->pSelect = pSelect;

View File

@ -908,7 +908,7 @@ sqlite3_value *sqlite3ValueNew(sqlite3 *db){
p->flags = MEM_Null;
p->type = SQLITE_NULL;
p->db = db;
}else{
}else if( db ){
db->mallocFailed = 1;
}
return p;

View File

@ -8,20 +8,22 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail. This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.43 2007/08/16 04:39:01 danielk1977 Exp $
# This file attempts to check the behavior of the SQLite library in
# an out-of-memory situation. When compiled with -DSQLITE_DEBUG=1,
# the SQLite library accepts a special command (sqlite3_memdebug_fail N C)
# which causes the N-th malloc to fail. This special feature is used
# to see what happens in the library if a malloc were to really fail
# due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.44 2007/08/22 20:18:22 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
ifcapable !memdebug {
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
finish_test
return
@ -182,7 +184,7 @@ do_malloc_test 7 -sqlprep {
SELECT min(a) FROM t1 WHERE a<6 GROUP BY b;
SELECT a FROM t1 WHERE a<6 ORDER BY a;
SELECT b FROM t1 WHERE a>6;
}
}
# This block is designed to test that some malloc failures that may
# occur in vdbeapi.c. Specifically, if a malloc failure that occurs
@ -197,9 +199,10 @@ do_malloc_test 7 -sqlprep {
# These tests only run if UTF-16 support is compiled in.
#
if {$::sqlite_options(utf16)} {
set ::STMT {}
do_malloc_test 8 -tclprep {
set sql "SELECT '[string repeat abc 20]', '[string repeat def 20]', ?"
set ::STMT [sqlite3_prepare $::DB $sql -1 X]
set ::STMT [sqlite3_prepare db $sql -1 X]
sqlite3_step $::STMT
if { $::tcl_platform(byteOrder)=="littleEndian" } {
set ::bomstr "\xFF\xFE"
@ -214,12 +217,15 @@ if {$::sqlite_options(utf16)} {
sqlite3_column_double $::STMT 1
sqlite3_reset $::STMT
sqlite3_bind_text16 $::STMT 1 $::bomstr 60
catch {sqlite3_finalize $::STMT}
if {[lindex [sqlite_malloc_stat] 2]<=0} {
error "out of memory"
}
#catch {sqlite3_finalize $::STMT}
#if {[lindex [sqlite_malloc_stat] 2]<=0} {
# error "out of memory"
#}
} -cleanup {
sqlite3_finalize $::STMT
if {$::STMT!=""} {
sqlite3_finalize $::STMT
set ::STMT {}
}
}
}
@ -250,8 +256,8 @@ do_malloc_test 10 -sqlprep {
# This block tests malloc() failures that occur within calls to
# sqlite3_create_function().
do_malloc_test 11 -tclbody {
set rc [sqlite3_create_function $::DB]
do_malloc_test 11 -tclbody {
set rc [sqlite3_create_function db]
if {[string match $rc SQLITE_NOMEM]} {
error "out of memory"
}
@ -260,7 +266,7 @@ do_malloc_test 11 -tclbody {
do_malloc_test 12 -tclbody {
set sql16 [encoding convertto unicode "SELECT * FROM sqlite_master"]
append sql16 "\00\00"
set ::STMT [sqlite3_prepare16 $::DB $sql16 -1 DUMMY]
set ::STMT [sqlite3_prepare16 db $sql16 -1 DUMMY]
sqlite3_finalize $::STMT
}
@ -320,9 +326,9 @@ proc string_compare {a b} {
# Test for malloc() failures in sqlite3_create_collation() and
# sqlite3_create_collation16().
#
do_malloc_test 15 -tclbody {
do_malloc_test 15 -start 4 -tclbody {
db collate string_compare string_compare
if {[catch {add_test_collate $::DB 1 1 1} msg]} {
if {[catch {add_test_collate db 1 1 1} msg]} {
if {$msg=="SQLITE_NOMEM"} {set msg "out of memory"}
error $msg
}
@ -423,7 +429,7 @@ do_malloc_test 19 -tclprep {
} -tclbody {
unset -nocomplain ::STMT
set r [catch {
set ::STMT [sqlite3_prepare $::DB {SELECT ?} -1 DUMMY]
set ::STMT [sqlite3_prepare db {SELECT ?} -1 DUMMY]
sqlite3_bind_text16 -static $::STMT 1 $static_string 112
} msg]
if {$r} {error [string range $msg 4 end]}
@ -466,7 +472,7 @@ do_malloc_test 22 -tclbody {
set ::STMT ""
set r [catch {
set ::STMT [
sqlite3_prepare_v2 $::DB "SELECT * FROM sqlite_master" -1 DUMMY
sqlite3_prepare_v2 db "SELECT * FROM sqlite_master" -1 DUMMY
]
} msg]
if {$r} {error [string range $msg 4 end]}
@ -484,5 +490,4 @@ do_test malloc-99.X {
} {0}
puts open-file-count=$sqlite_open_file_count
sqlite_malloc_fail 0
finish_test

View File

@ -30,22 +30,25 @@ proc do_malloc_test {tn args} {
if {[string is integer $tn]} {
set tn malloc-$tn
}
if {[info exists ::mallocopts(-start)]} {
set start $::mallocopts(-start)
} else {
set start 1
}
set ::go 1
for {set ::n 1} {$::go && $::n < 50000} {incr ::n} {
for {set ::n $start} {$::go && $::n < 50000} {incr ::n} {
do_test $tn.$::n {
# Remove all traces of database files test.db and test2.db from the files
# system. Then open (empty database) "test.db" with the handle [db].
#
sqlite_malloc_fail 0
catch {db close}
catch {file delete -force test.db}
catch {file delete -force test.db-journal}
catch {file delete -force test2.db}
catch {file delete -force test2.db-journal}
catch {sqlite3 db test.db}
set ::DB [sqlite3_connection_pointer db]
# Execute any -tclprep and -sqlprep scripts.
#
@ -59,7 +62,7 @@ proc do_malloc_test {tn args} {
# Now set the ${::n}th malloc() to fail and execute the -tclbody and
# -sqlbody scripts.
#
sqlite_malloc_fail $::n
sqlite3_memdebug_fail $::n 1
set ::mallocbody {}
if {[info exists ::mallocopts(-tclbody)]} {
append ::mallocbody "$::mallocopts(-tclbody)\n"
@ -68,28 +71,26 @@ proc do_malloc_test {tn args} {
append ::mallocbody "db eval {$::mallocopts(-sqlbody)}"
}
set v [catch $::mallocbody msg]
set failFlag [sqlite3_memdebug_fail -1 0]
set go [expr {$failFlag>0}]
# If the test fails (if $v!=0) and the database connection actually
# exists, make sure the failure code is SQLITE_NOMEM.
if {$v && [info command db]=="db" && [info exists ::mallocopts(-sqlbody)]
&& [db errorcode]!=7} {
set v 999
}
set leftover [lindex [sqlite_malloc_stat] 2]
if {$leftover>0} {
if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v Message=$msg"}
set ::go 0
if {$failFlag==0} {
if {$v} {
puts "\nError message returned: $msg"
set v2 $msg
} else {
set v {1 1}
set v 1
set v2 1
}
} elseif {!$v} {
set v2 $msg
} elseif {[info command db]=="" || [db errorcode]==7
|| $msg=="out of memory"} {
set v2 1
} else {
set v2 [expr {$msg=="" || $msg=="out of memory"}]
if {!$v2} {puts "\nError message returned: $msg"}
lappend v $v2
set v2 $msg
}
lappend v $v2
} {1 1}
if {[info exists ::mallocopts(-cleanup)]} {
@ -98,4 +99,3 @@ proc do_malloc_test {tn args} {
}
unset ::mallocopts
}

View File

@ -10,14 +10,14 @@
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# $Id: misc7.test,v 1.14 2007/06/27 23:52:18 drh Exp $
# $Id: misc7.test,v 1.15 2007/08/22 20:18:22 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test misc7-1 {
c_misuse_test
} {}
#do_test misc7-1 {
# c_misuse_test
#} {}
do_test misc7-2 {
c_realloc_test

View File

@ -11,7 +11,7 @@
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.84 2007/08/20 14:23:44 danielk1977 Exp $
# $Id: tester.tcl,v 1.85 2007/08/22 20:18:22 drh Exp $
# Make sure tclsqlite3 was compiled correctly. Abort now with an
# error message if not.
@ -208,7 +208,9 @@ proc finalize_testing {} {
sqlite3_soft_heap_limit 0
incr nTest
puts "$nErr errors out of $nTest tests"
puts "Failures on these tests: $::failList"
if {$nErr>0} {
puts "Failures on these tests: $::failList"
}
if {$nErr>0 && ![working_64bit_int]} {
puts "******************************************************************"
puts "N.B.: The version of TCL that you used to build this test harness"
@ -221,6 +223,13 @@ proc finalize_testing {} {
puts "$sqlite_open_file_count files were left open"
incr nErr
}
if {[sqlite3_memory_used]>0} {
puts "Unfreed memory: [sqlite3_memory_used] bytes"
incr nErr
} else {
puts "All memory allocations freed - no leaks"
}
puts "Maximum memory usage: [sqlite3_memory_highwater] bytes"
foreach f [glob -nocomplain test.db-*-journal] {
file delete -force $f
}
@ -562,8 +571,8 @@ proc copy_file {from to} {
}
}
# This command checks for outstanding calls to sqliteMalloc() from within
# the current thread. A list is returned with one entry for each outstanding
# This command checks for outstanding calls to sqlite3_malloc()
# A list is returned with one entry for each outstanding
# malloc. Each list entry is itself a list of 5 items, as follows:
#
# { <number-bytes> <file-name> <line-number> <test-case> <stack-dump> }