Make sure all memory from sqlite3DbMalloc() is freed by sqlite3DbFree() and
all memory from sqlite3_malloc() is freed by sqlite3_free(). FossilOrigin-Name: ac1f37a647e9ed1c00a901d26d9956a86c40117a
This commit is contained in:
parent
5419ee5f2f
commit
b975598ea0
64
manifest
64
manifest
@ -1,8 +1,8 @@
|
||||
-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA1
|
||||
|
||||
C Fix\sa\stypo\sin\sthe\sOS/2\svfs\scode.
|
||||
D 2010-07-23T22:26:21
|
||||
C Make\ssure\sall\smemory\sfrom\ssqlite3DbMalloc()\sis\sfreed\sby\ssqlite3DbFree()\sand\nall\smemory\sfrom\ssqlite3_malloc()\sis\sfreed\sby\ssqlite3_free().
|
||||
D 2010-07-24T16:34:38
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -110,17 +110,17 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
||||
F src/alter.c 8dc27638e7e2553e80b2b621f232be5eb1e85ef3
|
||||
F src/analyze.c 4ffed15a35cb669920348365fe71ce4d8800dc28
|
||||
F src/analyze.c c1bcd04b720e3300edafcdfe8bd2ba6bd9a8dca8
|
||||
F src/attach.c 17bec1f18254d9341369f20f90ba24ce35d20d10
|
||||
F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
|
||||
F src/backup.c 51d83300fe0baee39405c416ceb19a58ed30a8ed
|
||||
F src/bitvec.c 06ad2c36a9c3819c0b9cbffec7b15f58d5d834e0
|
||||
F src/btmutex.c 96a12f50f7a17475155971a241d85ec5171573ff
|
||||
F src/btree.c 9a214e6141555b183216b73ace058c7a499cdbe2
|
||||
F src/btree.c ed454f53f7bf7fb89c7a89f93fa93c5cd35e7aae
|
||||
F src/btree.h dd83041eda10c17daf023257c1fc883b5f71f85a
|
||||
F src/btreeInt.h b0c87f6725b06a0aa194a6d25d54b16ce9d6e291
|
||||
F src/build.c 8ccdb8ff8e86cbf5b891d4b236e50a91e69732d3
|
||||
F src/callback.c 4e565b7f387e3261a19ecaf0cbbdebfb91988ea4
|
||||
F src/build.c 6d3bd01296ac236f50519ec74711a38c8cee4fd7
|
||||
F src/callback.c da3c38d0ef5d7f04fae371e519bda61aa9cb1704
|
||||
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
||||
F src/ctime.c 4f3aadad62c6c9f0d4e5a96718516ac4e3c598df
|
||||
F src/date.c 5dd8448a0bfea8d31fb14cff487d0c06ff8c8b20
|
||||
@ -128,21 +128,21 @@ F src/delete.c 7ed8a8c8b5f748ece92df173d7e0f7810c899ebd
|
||||
F src/expr.c 7490fc3b16414d1a45d5acadf559317f9244891f
|
||||
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
||||
F src/fkey.c 62eed881a26a93e576b8cfeedea91952c90a8666
|
||||
F src/func.c 0c28599430856631216b6c0131c51c89bf516026
|
||||
F src/func.c 75dc1fd91e5692cadb80d257bab68d7343060467
|
||||
F src/global.c 02335177cf6946fe5525c6f0755cf181140debf3
|
||||
F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af
|
||||
F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970
|
||||
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
|
||||
F src/insert.c d9476f23f85a20eea3cc25a4b9f9cbae77a33bf2
|
||||
F src/insert.c ba455ebb100283ccc5da03da3498fcbca48ce6bb
|
||||
F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e
|
||||
F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
|
||||
F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
|
||||
F src/loadext.c 1c7a61ce1281041f437333f366a96aa0d29bb581
|
||||
F src/loadext.c 6d422ea91cf3d2d00408c5a8f2391cd458da85f8
|
||||
F src/main.c a487fe90aecaccb142e4a6b738c7e26e99145bcd
|
||||
F src/malloc.c f8b9bcd134ebfc95103d6834882567e66176d455
|
||||
F src/malloc.c 8394eba1c319a6d840ee411e23966d53a87f745a
|
||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||
F src/mem1.c 89d4ea8d5cdd55635cbaa48ad53132af6294cbb2
|
||||
F src/mem2.c 2ee7bdacda8299b5a91cff9f7ee3e46573195c38
|
||||
F src/mem2.c 716e62689d49b01ee742be6c745b1c3bbfbccd18
|
||||
F src/mem3.c 9b237d911ba9904142a804be727cc6664873f8a3
|
||||
F src/mem5.c eb7a5cb98915dd7a086fa415ce3a5a0f20d0acff
|
||||
F src/memjournal.c 4a93a25ad9f76c40afa070ffd7187eb3a5fd7aee
|
||||
@ -152,7 +152,7 @@ F src/mutex_noop.c d5cfbca87168c661a0b118cd8e329a908e453151
|
||||
F src/mutex_os2.c 6a62583e374ba3ac1a3fcc0da2bfdac7d3942689
|
||||
F src/mutex_unix.c cf84466b4fdd2baa0d5a10bb19f08b2abc1ce42e
|
||||
F src/mutex_w32.c 1fe0e735897be20e09dd6f53c3fb516c6b48c0eb
|
||||
F src/notify.c cbfa66a836da3a51567209636e6a94059c137930
|
||||
F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30
|
||||
F src/os.c 60178f518c4d6c0dcb59f7292232281d7bea2dcf
|
||||
F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9
|
||||
F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
|
||||
@ -165,9 +165,9 @@ F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
|
||||
F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07
|
||||
F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050
|
||||
F src/pcache1.c 3a7c28f46a61b43ff0b5c087a7983c154f4b264c
|
||||
F src/pragma.c 4a79269ea6f86150fb8e44688c753989fc7238dd
|
||||
F src/pragma.c 8b24ce00a93de345b6c3bd1e1e2cfba9f63d2325
|
||||
F src/prepare.c f045aeff869d6409a2eae2fe08f7dc2df9528195
|
||||
F src/printf.c 5f5b65a83e63f2096a541a340722a509fa0240a7
|
||||
F src/printf.c 8ae5082dd38a1b5456030c3755ec3a392cd51506
|
||||
F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
|
||||
F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706
|
||||
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
|
||||
@ -175,7 +175,7 @@ F src/select.c 74fef1334bec27e606ef0b19e5c41cd0a639e69c
|
||||
F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714
|
||||
F src/sqlite.h.in 2585fc82c922f2772e201e60a76d5fd1ca18370e
|
||||
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
|
||||
F src/sqliteInt.h 13819304fa198f4a3ff0e6aa8d3a94df662d2829
|
||||
F src/sqliteInt.h e24b335bd57f673c39a9098fdc98d8ad2d5dc3da
|
||||
F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
|
||||
F src/status.c e2ad9f18c16209dab501e26020590fcebb2b751b
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
@ -183,11 +183,11 @@ F src/tclsqlite.c ae1e4fb653c91ddad7e2534d209711a12604ccc4
|
||||
F src/test1.c ff3b4533fc4d78d1bff2ef831a5791db55096ed3
|
||||
F src/test2.c e3f564ab1e9fd0b47b0c9e23e7054e38bf0836cf
|
||||
F src/test3.c 4c21700c73a890a47fc685c1097bfb661346ac94
|
||||
F src/test4.c ad03bb987ddedce928f4258c1e7fa4109a73497d
|
||||
F src/test5.c cc55900118fa4add8ec9cf69fc4225a4662f76b1
|
||||
F src/test4.c 0528360b5025688002a5feb6be906ddce52eaaee
|
||||
F src/test5.c e1a19845625144caf038031234a12185e40d315c
|
||||
F src/test6.c c7256cc21d2409486d094277d5b017e8eced44ba
|
||||
F src/test7.c 3f2d63e4ccf97f8c2cf1a7fa0a3c8e2e2a354e6e
|
||||
F src/test8.c f959db9a22d882013b64c92753fa793b2ce3bdea
|
||||
F src/test7.c d67f65d82815eb0b57699b122ca0145dbea55bbb
|
||||
F src/test8.c 6b1d12912a04fe6fca8c45bb9c3ea022f4352228
|
||||
F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60
|
||||
F src/test_async.c 0612a752896fad42d55c3999a5122af10dcf22ad
|
||||
F src/test_autoext.c 30e7bd98ab6d70a62bb9ba572e4c7df347fe645e
|
||||
@ -215,25 +215,25 @@ F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa
|
||||
F src/test_thread.c bedd05cad673dba53326f3aa468cc803038896c0
|
||||
F src/test_vfs.c 7e291f85256516ebde6633bc381ff7eedfa30234
|
||||
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
|
||||
F src/tokenize.c eb58d4eabbc9dcc1d1efe7430641a1e651f30607
|
||||
F src/tokenize.c 604607d6813e9551cf5189d899e0a25c12681080
|
||||
F src/trigger.c 67e95c76d625b92d43409ace771c8e0d02a09ac2
|
||||
F src/update.c 19c899c23cd29fd102c9068e0b0ff5b087204beb
|
||||
F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
|
||||
F src/util.c 32aebf04c10e51ad3977a928b7416bed671b620b
|
||||
F src/vacuum.c 241a8386727c1497eba4955933356dfba6ff8c9f
|
||||
F src/vdbe.c 6294de3327e09d14e9c06ecfd10e57c2d8e85307
|
||||
F src/vdbe.c cefff41564b68a412e65e6a1013ec1b1c1ece6c4
|
||||
F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
|
||||
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
|
||||
F src/vdbeapi.c dc3138f10afbc95ed3c21dd25abb154504b1db9d
|
||||
F src/vdbeaux.c 7f99c1f00e4b31e8b28d8a87ecc2322bb46ae99c
|
||||
F src/vdbeaux.c e102e50a86f55e0598f0dd63480688e8123ead49
|
||||
F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
|
||||
F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
|
||||
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
|
||||
F src/vtab.c 4b09cb71090b8a9ce8fdc451816ed2bd62861dcc
|
||||
F src/vtab.c 838248ec64b1eda7afdf9303df30e8f1b96bc60f
|
||||
F src/wal.c 0925601f3299c2941a67c9cfff41ee710f70ca82
|
||||
F src/wal.h 906c85760598b18584921fe08008435aa4eeeeb2
|
||||
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
|
||||
F src/where.c 62262cee281c859ae136a40371f68a869b59ea1a
|
||||
F src/where.c 79202ca81e740eeb1f54512147e29b6c518d84ca
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
|
||||
F test/all.test 6745008c144bd2956d58864d21f7b304689c1cce
|
||||
@ -841,14 +841,18 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P 54e5886d841af69c8fa965bbcd637441d4a398ba
|
||||
R 691d9a52bb7cbfd5e8dcb9749da71253
|
||||
P a6bb2108bfb562a7067ef6150e43382736c0c4f5
|
||||
R 57ad848eef21f87b491f957007f9c787
|
||||
T *bgcolor * #a0c0f0
|
||||
T *branch * malloc-enhancement
|
||||
T *sym-malloc-enhancement *
|
||||
T -sym-trunk *
|
||||
U drh
|
||||
Z 52e232c87c73a10044c307be36db6f45
|
||||
Z 0e50e08d3aab5ed9a84c7eabe091b80c
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||
|
||||
iD8DBQFMShcQoxKgR168RlERAmjGAJoCLXWaZ2DuRMaoWPWt76CoNmu7twCfbMSo
|
||||
7kHJSzk9KhxmMxRjeT/UwcA=
|
||||
=7tfR
|
||||
iD8DBQFMSxYioxKgR168RlERAgv5AJwKcCKth9vEcMrMziFc3bR3CMKXOgCeOwNK
|
||||
xsMH21OEzgn+77HK/85/56Q=
|
||||
=jlvX
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@ -1 +1 @@
|
||||
a6bb2108bfb562a7067ef6150e43382736c0c4f5
|
||||
ac1f37a647e9ed1c00a901d26d9956a86c40117a
|
@ -591,7 +591,7 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
|
||||
|
||||
if( pIdx->aSample==0 ){
|
||||
static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
|
||||
pIdx->aSample = (IndexSample *)sqlite3Malloc(sz);
|
||||
pIdx->aSample = (IndexSample *)sqlite3DbMallocRaw(0, sz);
|
||||
if( pIdx->aSample==0 ){
|
||||
db->mallocFailed = 1;
|
||||
break;
|
||||
|
@ -2004,7 +2004,7 @@ int sqlite3BtreeClose(Btree *p){
|
||||
if( pBt->xFreeSchema && pBt->pSchema ){
|
||||
pBt->xFreeSchema(pBt->pSchema);
|
||||
}
|
||||
sqlite3_free(pBt->pSchema);
|
||||
sqlite3DbFree(0, pBt->pSchema);
|
||||
freeTempSpace(pBt);
|
||||
sqlite3_free(pBt);
|
||||
}
|
||||
@ -7749,6 +7749,7 @@ char *sqlite3BtreeIntegrityCheck(
|
||||
sCheck.anRef[i] = 1;
|
||||
}
|
||||
sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), 20000);
|
||||
sCheck.errMsg.useMalloc = 2;
|
||||
|
||||
/* Check the integrity of the freelist
|
||||
*/
|
||||
@ -7886,7 +7887,7 @@ void *sqlite3BtreeSchema(Btree *p, int nBytes, void(*xFree)(void *)){
|
||||
BtShared *pBt = p->pBt;
|
||||
sqlite3BtreeEnter(p);
|
||||
if( !pBt->pSchema && nBytes ){
|
||||
pBt->pSchema = sqlite3MallocZero(nBytes);
|
||||
pBt->pSchema = sqlite3DbMallocZero(0, nBytes);
|
||||
pBt->xFreeSchema = xFree;
|
||||
}
|
||||
sqlite3BtreeLeave(p);
|
||||
|
@ -1367,7 +1367,7 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
||||
zEnd = "\n)";
|
||||
}
|
||||
n += 35 + 6*p->nCol;
|
||||
zStmt = sqlite3Malloc( n );
|
||||
zStmt = sqlite3DbMallocRaw(0, n);
|
||||
if( zStmt==0 ){
|
||||
db->mallocFailed = 1;
|
||||
return 0;
|
||||
@ -2814,7 +2814,7 @@ Index *sqlite3CreateIndex(
|
||||
/* Clean up before exiting */
|
||||
exit_create_index:
|
||||
if( pIndex ){
|
||||
sqlite3_free(pIndex->zColAff);
|
||||
sqlite3DbFree(db, pIndex->zColAff);
|
||||
sqlite3DbFree(db, pIndex);
|
||||
}
|
||||
sqlite3ExprListDelete(db, pList);
|
||||
|
@ -439,7 +439,7 @@ Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
|
||||
if( pBt ){
|
||||
p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
|
||||
}else{
|
||||
p = (Schema *)sqlite3MallocZero(sizeof(Schema));
|
||||
p = (Schema *)sqlite3DbMallocZero(0, sizeof(Schema));
|
||||
}
|
||||
if( !p ){
|
||||
db->mallocFailed = 1;
|
||||
|
@ -1010,14 +1010,14 @@ static void replaceFunc(
|
||||
testcase( nOut-2==db->aLimit[SQLITE_LIMIT_LENGTH] );
|
||||
if( nOut-1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
|
||||
sqlite3_result_error_toobig(context);
|
||||
sqlite3DbFree(db, zOut);
|
||||
sqlite3_free(zOut);
|
||||
return;
|
||||
}
|
||||
zOld = zOut;
|
||||
zOut = sqlite3_realloc(zOut, (int)nOut);
|
||||
if( zOut==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
sqlite3DbFree(db, zOld);
|
||||
sqlite3_free(zOld);
|
||||
return;
|
||||
}
|
||||
memcpy(&zOut[j], zRep, nRep);
|
||||
@ -1378,7 +1378,7 @@ static void groupConcatStep(
|
||||
if( pAccum ){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
int firstTerm = pAccum->useMalloc==0;
|
||||
pAccum->useMalloc = 1;
|
||||
pAccum->useMalloc = 2;
|
||||
pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
|
||||
if( !firstTerm ){
|
||||
if( argc==2 ){
|
||||
|
@ -67,7 +67,7 @@ const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
|
||||
int n;
|
||||
Table *pTab = pIdx->pTable;
|
||||
sqlite3 *db = sqlite3VdbeDb(v);
|
||||
pIdx->zColAff = (char *)sqlite3Malloc(pIdx->nColumn+2);
|
||||
pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+2);
|
||||
if( !pIdx->zColAff ){
|
||||
db->mallocFailed = 1;
|
||||
return 0;
|
||||
@ -109,7 +109,7 @@ void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
|
||||
int i;
|
||||
sqlite3 *db = sqlite3VdbeDb(v);
|
||||
|
||||
zColAff = (char *)sqlite3Malloc(pTab->nCol+1);
|
||||
zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
|
||||
if( !zColAff ){
|
||||
db->mallocFailed = 1;
|
||||
return;
|
||||
|
@ -376,13 +376,11 @@ static int sqlite3LoadExtension(
|
||||
handle = sqlite3OsDlOpen(pVfs, zFile);
|
||||
if( handle==0 ){
|
||||
if( pzErrMsg ){
|
||||
zErrmsg = sqlite3StackAllocZero(db, nMsg);
|
||||
*pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
|
||||
if( zErrmsg ){
|
||||
sqlite3_snprintf(nMsg, zErrmsg,
|
||||
"unable to open shared library [%s]", zFile);
|
||||
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
|
||||
*pzErrMsg = sqlite3DbStrDup(0, zErrmsg);
|
||||
sqlite3StackFree(db, zErrmsg);
|
||||
}
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
@ -391,13 +389,11 @@ static int sqlite3LoadExtension(
|
||||
sqlite3OsDlSym(pVfs, handle, zProc);
|
||||
if( xInit==0 ){
|
||||
if( pzErrMsg ){
|
||||
zErrmsg = sqlite3StackAllocZero(db, nMsg);
|
||||
*pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
|
||||
if( zErrmsg ){
|
||||
sqlite3_snprintf(nMsg, zErrmsg,
|
||||
"no entry point [%s] in shared library [%s]", zProc,zFile);
|
||||
sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
|
||||
*pzErrMsg = sqlite3DbStrDup(0, zErrmsg);
|
||||
sqlite3StackFree(db, zErrmsg);
|
||||
}
|
||||
sqlite3OsDlClose(pVfs, handle);
|
||||
}
|
||||
|
16
src/malloc.c
16
src/malloc.c
@ -368,6 +368,7 @@ void sqlite3ScratchFree(void *p){
|
||||
|| p<sqlite3GlobalConfig.pScratch
|
||||
|| p>=(void*)mem0.aScratchFree ){
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
|
||||
assert( !sqlite3MemdebugHasType(p, ~MEMTYPE_SCRATCH) );
|
||||
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
|
||||
if( sqlite3GlobalConfig.bMemstat ){
|
||||
int iSize = sqlite3MallocSize(p);
|
||||
@ -420,6 +421,7 @@ static int isLookaside(sqlite3 *db, void *p){
|
||||
*/
|
||||
int sqlite3MallocSize(void *p){
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
|
||||
assert( !sqlite3MemdebugHasType(p, MEMTYPE_RECURSIVE) );
|
||||
return sqlite3GlobalConfig.m.xSize(p);
|
||||
}
|
||||
int sqlite3DbMallocSize(sqlite3 *db, void *p){
|
||||
@ -427,6 +429,7 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){
|
||||
if( isLookaside(db, p) ){
|
||||
return db->lookaside.sz;
|
||||
}else{
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_RECURSIVE) );
|
||||
assert( sqlite3MemdebugHasType(p,
|
||||
db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
|
||||
return sqlite3GlobalConfig.m.xSize(p);
|
||||
@ -438,6 +441,7 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){
|
||||
*/
|
||||
void sqlite3_free(void *p){
|
||||
if( p==0 ) return;
|
||||
assert( !sqlite3MemdebugHasType(p, MEMTYPE_RECURSIVE) );
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
|
||||
if( sqlite3GlobalConfig.bMemstat ){
|
||||
sqlite3_mutex_enter(mem0.mutex);
|
||||
@ -461,6 +465,7 @@ void sqlite3DbFree(sqlite3 *db, void *p){
|
||||
db->lookaside.pFree = pBuf;
|
||||
db->lookaside.nOut--;
|
||||
}else{
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_RECURSIVE) );
|
||||
assert( sqlite3MemdebugHasType(p,
|
||||
db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
|
||||
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
|
||||
@ -497,6 +502,7 @@ void *sqlite3Realloc(void *pOld, int nBytes){
|
||||
sqlite3MallocAlarm(nNew-nOld);
|
||||
}
|
||||
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
|
||||
assert( !sqlite3MemdebugHasType(pOld, ~MEMTYPE_HEAP) );
|
||||
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
|
||||
if( pNew==0 && mem0.alarmCallback ){
|
||||
sqlite3MallocAlarm(nBytes);
|
||||
@ -594,8 +600,8 @@ void *sqlite3DbMallocRaw(sqlite3 *db, int n){
|
||||
if( !p && db ){
|
||||
db->mallocFailed = 1;
|
||||
}
|
||||
sqlite3MemdebugSetType(p,
|
||||
(db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP);
|
||||
sqlite3MemdebugSetType(p, MEMTYPE_RECURSIVE |
|
||||
((db && db->lookaside.bEnabled) ? MEMTYPE_DB : MEMTYPE_HEAP));
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -621,14 +627,16 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
|
||||
sqlite3DbFree(db, p);
|
||||
}
|
||||
}else{
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_RECURSIVE) );
|
||||
assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
|
||||
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
|
||||
pNew = sqlite3_realloc(p, n);
|
||||
if( !pNew ){
|
||||
sqlite3MemdebugSetType(p, MEMTYPE_RECURSIVE|MEMTYPE_HEAP);
|
||||
db->mallocFailed = 1;
|
||||
}
|
||||
sqlite3MemdebugSetType(pNew,
|
||||
db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
|
||||
sqlite3MemdebugSetType(pNew, MEMTYPE_RECURSIVE |
|
||||
(db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP));
|
||||
}
|
||||
}
|
||||
return pNew;
|
||||
|
@ -401,13 +401,7 @@ int sqlite3MemdebugHasType(void *p, u8 eType){
|
||||
struct MemBlockHdr *pHdr;
|
||||
pHdr = sqlite3MemsysGetHeader(p);
|
||||
assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
|
||||
assert( (pHdr->eType & (pHdr->eType-1))==0 ); /* Only one type bit set */
|
||||
if( (pHdr->eType&eType)==0 ){
|
||||
void **pBt;
|
||||
pBt = (void**)pHdr;
|
||||
pBt -= pHdr->nBacktraceSlots;
|
||||
backtrace_symbols_fd(pBt, pHdr->nBacktrace, fileno(stderr));
|
||||
fprintf(stderr, "\n");
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ void sqlite3ConnectionUnlocked(sqlite3 *db){
|
||||
assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
|
||||
assert( nArg<=(int)ArraySize(aStatic) || aArg==aDyn );
|
||||
if( (!aDyn && nArg==(int)ArraySize(aStatic))
|
||||
|| (aDyn && nArg==(int)(sqlite3DbMallocSize(db, aDyn)/sizeof(void*)))
|
||||
|| (aDyn && nArg==(int)(sqlite3MallocSize(aDyn)/sizeof(void*)))
|
||||
){
|
||||
/* The aArg[] array needs to grow. */
|
||||
void **pNew = (void **)sqlite3Malloc(nArg*sizeof(void *)*2);
|
||||
|
@ -765,7 +765,7 @@ void sqlite3Pragma(
|
||||
}
|
||||
sqlite3_free(sqlite3_temp_directory);
|
||||
if( zRight[0] ){
|
||||
sqlite3_temp_directory = sqlite3DbStrDup(0, zRight);
|
||||
sqlite3_temp_directory = sqlite3_mprintf("%s", zRight);
|
||||
}else{
|
||||
sqlite3_temp_directory = 0;
|
||||
}
|
||||
|
19
src/printf.c
19
src/printf.c
@ -772,7 +772,11 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
|
||||
}else{
|
||||
p->nAlloc = (int)szNew;
|
||||
}
|
||||
zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
|
||||
if( p->useMalloc==1 ){
|
||||
zNew = sqlite3DbMallocRaw(p->db, p->nAlloc );
|
||||
}else{
|
||||
zNew = sqlite3_malloc(p->nAlloc);
|
||||
}
|
||||
if( zNew ){
|
||||
memcpy(zNew, p->zText, p->nChar);
|
||||
sqlite3StrAccumReset(p);
|
||||
@ -797,7 +801,11 @@ char *sqlite3StrAccumFinish(StrAccum *p){
|
||||
if( p->zText ){
|
||||
p->zText[p->nChar] = 0;
|
||||
if( p->useMalloc && p->zText==p->zBase ){
|
||||
p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
|
||||
if( p->useMalloc==1 ){
|
||||
p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
|
||||
}else{
|
||||
p->zText = sqlite3_malloc(p->nChar+1);
|
||||
}
|
||||
if( p->zText ){
|
||||
memcpy(p->zText, p->zBase, p->nChar+1);
|
||||
}else{
|
||||
@ -813,7 +821,11 @@ char *sqlite3StrAccumFinish(StrAccum *p){
|
||||
*/
|
||||
void sqlite3StrAccumReset(StrAccum *p){
|
||||
if( p->zText!=p->zBase ){
|
||||
sqlite3DbFree(p->db, p->zText);
|
||||
if( p->useMalloc==1 ){
|
||||
sqlite3DbFree(p->db, p->zText);
|
||||
}else{
|
||||
sqlite3_free(p->zText);
|
||||
}
|
||||
}
|
||||
p->zText = 0;
|
||||
}
|
||||
@ -895,6 +907,7 @@ char *sqlite3_vmprintf(const char *zFormat, va_list ap){
|
||||
if( sqlite3_initialize() ) return 0;
|
||||
#endif
|
||||
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
|
||||
acc.useMalloc = 2;
|
||||
sqlite3VXPrintf(&acc, 0, zFormat, ap);
|
||||
z = sqlite3StrAccumFinish(&acc);
|
||||
return z;
|
||||
|
@ -2325,7 +2325,7 @@ struct StrAccum {
|
||||
int nAlloc; /* Amount of space allocated in zText */
|
||||
int mxAlloc; /* Maximum allowed string length */
|
||||
u8 mallocFailed; /* Becomes true if any memory allocation fails */
|
||||
u8 useMalloc; /* True if zText is enlargeable using realloc */
|
||||
u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */
|
||||
u8 tooBig; /* Becomes true if string size exceeds limits */
|
||||
};
|
||||
|
||||
@ -3140,9 +3140,10 @@ SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...);
|
||||
# define sqlite3MemdebugSetType(X,Y) /* no-op */
|
||||
# define sqlite3MemdebugHasType(X,Y) 1
|
||||
#endif
|
||||
#define MEMTYPE_HEAP 0x01 /* General heap allocations */
|
||||
#define MEMTYPE_DB 0x02 /* Associated with a database connection */
|
||||
#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
|
||||
#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
|
||||
#define MEMTYPE_HEAP 0x01 /* General heap allocations */
|
||||
#define MEMTYPE_DB 0x02 /* Associated with a database connection */
|
||||
#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
|
||||
#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
|
||||
#define MEMTYPE_RECURSIVE 0x10 /* Experimental */
|
||||
|
||||
#endif /* _SQLITEINT_H_ */
|
||||
|
@ -142,7 +142,7 @@ static int tcl_thread_create(
|
||||
}
|
||||
threadset[i].busy = 1;
|
||||
sqlite3_free(threadset[i].zFilename);
|
||||
threadset[i].zFilename = sqlite3DbStrDup(0, argv[2]);
|
||||
threadset[i].zFilename = sqlite3_mprintf("%s", argv[2]);
|
||||
threadset[i].opnum = 1;
|
||||
threadset[i].completed = 0;
|
||||
rc = pthread_create(&x, 0, thread_main, &threadset[i]);
|
||||
@ -476,7 +476,7 @@ static int tcl_thread_compile(
|
||||
thread_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_compile;
|
||||
sqlite3_free(threadset[i].zArg);
|
||||
threadset[i].zArg = sqlite3DbStrDup(0, argv[2]);
|
||||
threadset[i].zArg = sqlite3_mprintf("%s", argv[2]);
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ static int test_translate(
|
||||
if( enc_from==SQLITE_UTF8 ){
|
||||
z = Tcl_GetString(objv[1]);
|
||||
if( objc==5 ){
|
||||
z = sqlite3DbStrDup(0, z);
|
||||
z = sqlite3_mprintf("%s", z);
|
||||
}
|
||||
sqlite3ValueSetStr(pVal, -1, z, enc_from, xDel);
|
||||
}else{
|
||||
|
@ -164,7 +164,7 @@ static int tcl_client_create(
|
||||
}
|
||||
threadset[i].busy = 1;
|
||||
sqlite3_free(threadset[i].zFilename);
|
||||
threadset[i].zFilename = sqlite3DbStrDup(0, argv[2]);
|
||||
threadset[i].zFilename = sqlite3_mprintf("%s", argv[2]);
|
||||
threadset[i].opnum = 1;
|
||||
threadset[i].completed = 0;
|
||||
rc = pthread_create(&x, 0, client_main, &threadset[i]);
|
||||
@ -507,7 +507,7 @@ static int tcl_client_compile(
|
||||
client_wait(&threadset[i]);
|
||||
threadset[i].xOp = do_compile;
|
||||
sqlite3_free(threadset[i].zArg);
|
||||
threadset[i].zArg = sqlite3DbStrDup(0, argv[2]);
|
||||
threadset[i].zArg = sqlite3_mprintf("%s", argv[2]);
|
||||
threadset[i].opnum++;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ static int echoCreate(
|
||||
rc = sqlite3_exec(db, zSql, 0, 0, 0);
|
||||
sqlite3_free(zSql);
|
||||
if( rc!=SQLITE_OK ){
|
||||
*pzErr = sqlite3DbStrDup(0, sqlite3_errmsg(db));
|
||||
*pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ abort_parse:
|
||||
}
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
sqlite3DbFree(db, pParse->apVtabLock);
|
||||
sqlite3_free(pParse->apVtabLock);
|
||||
#endif
|
||||
|
||||
if( !IN_DECLARE_VTAB ){
|
||||
|
48
src/vdbe.c
48
src/vdbe.c
@ -501,6 +501,20 @@ static int checkSavepointCount(sqlite3 *db){
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Transfer error message text from an sqlite3_vtab.zErrMsg (text stored
|
||||
** in memory obtained from sqlite3_malloc) into a Vdbe.zErrMsg (text stored
|
||||
** in memory obtained from sqlite3DbMalloc).
|
||||
*/
|
||||
static void importVtabErrMsg(Vdbe *p, sqlite3_vtab *pVtab){
|
||||
sqlite3 *db = p->db;
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
|
||||
sqlite3_free(pVtab->zErrMsg);
|
||||
pVtab->zErrMsg = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Execute as much of a VDBE program as we can then return.
|
||||
**
|
||||
@ -4030,9 +4044,7 @@ case OP_Rowid: { /* out2-prerelease */
|
||||
pModule = pVtab->pModule;
|
||||
assert( pModule->xRowid );
|
||||
rc = pModule->xRowid(pC->pVtabCursor, &v);
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
importVtabErrMsg(p, pVtab);
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
}else{
|
||||
assert( pC->pCursor!=0 );
|
||||
@ -5375,11 +5387,7 @@ case OP_VBegin: {
|
||||
VTable *pVTab;
|
||||
pVTab = pOp->p4.pVtab;
|
||||
rc = sqlite3VtabBegin(db, pVTab);
|
||||
if( pVTab ){
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVTab->pVtab->zErrMsg;
|
||||
pVTab->pVtab->zErrMsg = 0;
|
||||
}
|
||||
if( pVTab ) importVtabErrMsg(p, pVTab->pVtab);
|
||||
break;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
@ -5429,9 +5437,7 @@ case OP_VOpen: {
|
||||
pModule = (sqlite3_module *)pVtab->pModule;
|
||||
assert(pVtab && pModule);
|
||||
rc = pModule->xOpen(pVtab, &pVtabCursor);
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
importVtabErrMsg(p, pVtab);
|
||||
if( SQLITE_OK==rc ){
|
||||
/* Initialize sqlite3_vtab_cursor base class */
|
||||
pVtabCursor->pVtab = pVtab;
|
||||
@ -5508,9 +5514,7 @@ case OP_VFilter: { /* jump */
|
||||
p->inVtabMethod = 1;
|
||||
rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
|
||||
p->inVtabMethod = 0;
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
importVtabErrMsg(p, pVtab);
|
||||
if( rc==SQLITE_OK ){
|
||||
res = pModule->xEof(pVtabCursor);
|
||||
}
|
||||
@ -5560,9 +5564,7 @@ case OP_VColumn: {
|
||||
MemSetTypeFlag(&sContext.s, MEM_Null);
|
||||
|
||||
rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2);
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
importVtabErrMsg(p, pVtab);
|
||||
if( sContext.isError ){
|
||||
rc = sContext.isError;
|
||||
}
|
||||
@ -5615,9 +5617,7 @@ case OP_VNext: { /* jump */
|
||||
p->inVtabMethod = 1;
|
||||
rc = pModule->xNext(pCur->pVtabCursor);
|
||||
p->inVtabMethod = 0;
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
importVtabErrMsg(p, pVtab);
|
||||
if( rc==SQLITE_OK ){
|
||||
res = pModule->xEof(pCur->pVtabCursor);
|
||||
}
|
||||
@ -5647,9 +5647,7 @@ case OP_VRename: {
|
||||
REGISTER_TRACE(pOp->p1, pName);
|
||||
assert( pName->flags & MEM_Str );
|
||||
rc = pVtab->pModule->xRename(pVtab, pName->z);
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
importVtabErrMsg(p, pVtab);
|
||||
|
||||
break;
|
||||
}
|
||||
@ -5701,9 +5699,7 @@ case OP_VUpdate: {
|
||||
pX++;
|
||||
}
|
||||
rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid);
|
||||
sqlite3DbFree(db, p->zErrMsg);
|
||||
p->zErrMsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
importVtabErrMsg(p, pVtab);
|
||||
if( rc==SQLITE_OK && pOp->p1 ){
|
||||
assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) );
|
||||
db->lastRowid = rowid;
|
||||
|
@ -581,7 +581,6 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){
|
||||
switch( p4type ){
|
||||
case P4_REAL:
|
||||
case P4_INT64:
|
||||
case P4_MPRINTF:
|
||||
case P4_DYNAMIC:
|
||||
case P4_KEYINFO:
|
||||
case P4_INTARRAY:
|
||||
@ -589,6 +588,10 @@ static void freeP4(sqlite3 *db, int p4type, void *p4){
|
||||
sqlite3DbFree(db, p4);
|
||||
break;
|
||||
}
|
||||
case P4_MPRINTF: {
|
||||
sqlite3_free(p4);
|
||||
break;
|
||||
}
|
||||
case P4_VDBEFUNC: {
|
||||
VdbeFunc *pVdbeFunc = (VdbeFunc *)p4;
|
||||
freeEphemeralFunction(db, pVdbeFunc->pFunc);
|
||||
@ -739,7 +742,7 @@ void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int n){
|
||||
|
||||
nField = ((KeyInfo*)zP4)->nField;
|
||||
nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
|
||||
pKeyInfo = sqlite3Malloc( nByte );
|
||||
pKeyInfo = sqlite3DbMallocRaw(0, nByte);
|
||||
pOp->p4.pKeyInfo = pKeyInfo;
|
||||
if( pKeyInfo ){
|
||||
u8 *aSortOrder;
|
||||
|
@ -466,7 +466,7 @@ static int vtabCallConstructor(
|
||||
*pzErr = sqlite3MPrintf(db, "vtable constructor failed: %s", zModuleName);
|
||||
}else {
|
||||
*pzErr = sqlite3MPrintf(db, "%s", zErr);
|
||||
sqlite3DbFree(db, zErr);
|
||||
sqlite3_free(zErr);
|
||||
}
|
||||
sqlite3DbFree(db, pVTable);
|
||||
}else if( ALWAYS(pVTable->pVtab) ){
|
||||
@ -673,7 +673,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
|
||||
db->pVTab = 0;
|
||||
}else{
|
||||
sqlite3Error(db, SQLITE_ERROR, zErr);
|
||||
sqlite3DbFree(db, zErr);
|
||||
sqlite3_free(zErr);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
pParse->declareVtab = 0;
|
||||
@ -768,8 +768,8 @@ int sqlite3VtabSync(sqlite3 *db, char **pzErrmsg){
|
||||
if( pVtab && (x = pVtab->pModule->xSync)!=0 ){
|
||||
rc = x(pVtab);
|
||||
sqlite3DbFree(db, *pzErrmsg);
|
||||
*pzErrmsg = pVtab->zErrMsg;
|
||||
pVtab->zErrMsg = 0;
|
||||
*pzErrmsg = sqlite3DbStrDup(db, pVtab->zErrMsg);
|
||||
sqlite3_free(pVtab->zErrMsg);
|
||||
}
|
||||
}
|
||||
db->aVTrans = aVTrans;
|
||||
|
@ -2025,7 +2025,7 @@ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){
|
||||
sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);
|
||||
}
|
||||
}
|
||||
sqlite3DbFree(pParse->db, pVtab->zErrMsg);
|
||||
sqlite3_free(pVtab->zErrMsg);
|
||||
pVtab->zErrMsg = 0;
|
||||
|
||||
for(i=0; i<p->nConstraint; i++){
|
||||
|
Loading…
Reference in New Issue
Block a user