aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2010-07-26 11:07:20 +0000
committerdrh <drh@noemail.net>2010-07-26 11:07:20 +0000
commit174b9a166d293445dcc3075c292b78115b62be8f (patch)
tree1a5d8aeb2c14be45b0e4656208b0aec5815d5acf
parentd46def77db74a7dfadabb16da57c25d83af0c248 (diff)
parentb975598ea0b3dbb1145513b0adada002c3c581bb (diff)
downloadsqlite-174b9a166d293445dcc3075c292b78115b62be8f.tar.gz
sqlite-174b9a166d293445dcc3075c292b78115b62be8f.zip
Make sure all memory from sqlite3DbMalloc() is freed by sqlite3DbFree()
and all memory from sqlite3_malloc() is freed by sqlite3_free(). FossilOrigin-Name: 629e38a8c9e31111e351fe4625a5835576d23584
-rw-r--r--manifest69
-rw-r--r--manifest.uuid2
-rw-r--r--src/analyze.c8
-rw-r--r--src/btree.c5
-rw-r--r--src/build.c4
-rw-r--r--src/callback.c2
-rw-r--r--src/func.c6
-rw-r--r--src/insert.c4
-rw-r--r--src/loadext.c8
-rw-r--r--src/malloc.c54
-rw-r--r--src/mem2.c29
-rw-r--r--src/notify.c2
-rw-r--r--src/pragma.c2
-rw-r--r--src/printf.c19
-rw-r--r--src/sqliteInt.h30
-rw-r--r--src/test4.c4
-rw-r--r--src/test5.c2
-rw-r--r--src/test7.c4
-rw-r--r--src/test8.c2
-rw-r--r--src/tokenize.c2
-rw-r--r--src/vdbe.c48
-rw-r--r--src/vdbeaux.c7
-rw-r--r--src/vtab.c8
-rw-r--r--src/where.c2
24 files changed, 182 insertions, 141 deletions
diff --git a/manifest b/manifest
index 93627ae07..63d3b1cb9 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,8 @@
-C Experimental\scode\sto\smeasure\smemory\sconsumed\sby\sdatabase\sschemas\sand\sprepared\sstatements.
-D 2010-07-24T11:28:29
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+C Make\ssure\sall\smemory\sfrom\ssqlite3DbMalloc()\sis\sfreed\sby\ssqlite3DbFree()\nand\sall\smemory\sfrom\ssqlite3_malloc()\sis\sfreed\sby\ssqlite3_free().
+D 2010-07-26T11:07:21
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -107,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 6c2bdb1d13138d084b14010cd9fef4ff34e0d313
+F src/analyze.c 3642ebcd13f1ffb5773b9e08910e0492ec4cf946
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 fdf428a35c0bd6256373e7779f3744ad4c8ff2eb
-F src/callback.c 4e565b7f387e3261a19ecaf0cbbdebfb91988ea4
+F src/build.c d4593392b8bf0753dd16f494628823f6f39ee7fb
+F src/callback.c da3c38d0ef5d7f04fae371e519bda61aa9cb1704
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 4f3aadad62c6c9f0d4e5a96718516ac4e3c598df
F src/date.c 5dd8448a0bfea8d31fb14cff487d0c06ff8c8b20
@@ -125,21 +128,21 @@ F src/delete.c 7ed8a8c8b5f748ece92df173d7e0f7810c899ebd
F src/expr.c 7490fc3b16414d1a45d5acadf559317f9244891f
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c cacfe3e24b311e4e089a9c470bdb73196af6f729
-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 d321131022bd83f95f871cde212ddb01ed217f2f
+F src/malloc.c 1cf0f2f45926c40b638e85e9b67fe5fabd072829
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 89d4ea8d5cdd55635cbaa48ad53132af6294cbb2
-F src/mem2.c 2ee7bdacda8299b5a91cff9f7ee3e46573195c38
+F src/mem2.c 12c91260fd2320eda9355dea5445b137f848c05b
F src/mem3.c 9b237d911ba9904142a804be727cc6664873f8a3
F src/mem5.c eb7a5cb98915dd7a086fa415ce3a5a0f20d0acff
F src/memjournal.c 4a93a25ad9f76c40afa070ffd7187eb3a5fd7aee
@@ -149,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
@@ -162,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
@@ -172,7 +175,7 @@ F src/select.c 74fef1334bec27e606ef0b19e5c41cd0a639e69c
F src/shell.c fd4ccdb37c3b68de0623eb938a649e0990710714
F src/sqlite.h.in 05469b38a929b31278c7ed30b3d3f4b4e17817b6
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
-F src/sqliteInt.h 0ec613ec2fbb26a1f363425c945a22667d659af5
+F src/sqliteInt.h 2a057459f689e23514f0ac2c414ef900f5d02a71
F src/sqliteLimit.h 196e2f83c3b444c4548fc1874f52f84fdbda40f3
F src/status.c ab77d17fbfe0ab800b3c54dd6853e30b1dc1634e
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
@@ -180,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
@@ -212,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 7c5de1c7e2e6bc1f301bb95297aeb5d1b8455764
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
F src/vdbeapi.c dc3138f10afbc95ed3c21dd25abb154504b1db9d
-F src/vdbeaux.c 9f18d228ee96b26e10f908f8f9597c700347df71
+F src/vdbeaux.c 1616d797183a7b803124697bb4dfa883b3b6c12a
F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
-F src/vtab.c 74bc8e035f3762d3cab1498dbbf2117e798540a5
+F src/vtab.c 82200af3881fa4e1c9cf07cf31d98c09d437e3ab
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
@@ -838,10 +841,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P a6bb2108bfb562a7067ef6150e43382736c0c4f5
-R 5ce07ed2a0b02fd2492d8af031b47b67
-T *branch * experimental
-T *sym-experimental *
-T -sym-trunk *
-U dan
-Z 4780c44291ffd7692ca32c6ddced636f
+P 9aa30342f4de4eff630520ea8e07ad253d3f0877 ac1f37a647e9ed1c00a901d26d9956a86c40117a
+R 5e97c484f0c177ee87733094e898ae28
+U drh
+Z ed9a664d8006d5d1a2fa23f0a60137f2
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.6 (GNU/Linux)
+
+iD8DBQFMTWxtoxKgR168RlERAp5SAKCD5Wul3MvRW/uf5JygdrrU2/cnGACfcrvh
+hDUH6H64I7jMlSjVOLsS7f8=
+=ga4H
+-----END PGP SIGNATURE-----
diff --git a/manifest.uuid b/manifest.uuid
index 5222381d1..13f8d6fc8 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-9aa30342f4de4eff630520ea8e07ad253d3f0877 \ No newline at end of file
+629e38a8c9e31111e351fe4625a5835576d23584 \ No newline at end of file
diff --git a/src/analyze.c b/src/analyze.c
index d96deb3c2..42705cafd 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -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;
@@ -619,10 +619,8 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
if( n < 1){
pSample->u.z = 0;
}else{
- pSample->u.z = sqlite3Malloc(n);
- if( pSample->u.z ){
- memcpy(pSample->u.z, z, n);
- }else{
+ pSample->u.z = sqlite3DbStrNDup(0, z, n);
+ if( pSample->u.z==0 ){
db->mallocFailed = 1;
break;
}
diff --git a/src/btree.c b/src/btree.c
index f47614ac4..d07e4c3d6 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -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);
diff --git a/src/build.c b/src/build.c
index 989489f1e..1281af67e 100644
--- a/src/build.c
+++ b/src/build.c
@@ -1351,7 +1351,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;
@@ -2800,7 +2800,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);
diff --git a/src/callback.c b/src/callback.c
index f8918bcf1..fdcc9f9c0 100644
--- a/src/callback.c
+++ b/src/callback.c
@@ -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;
diff --git a/src/func.c b/src/func.c
index 8b1b2f71f..15d7a5bd6 100644
--- a/src/func.c
+++ b/src/func.c
@@ -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 ){
diff --git a/src/insert.c b/src/insert.c
index f6ad5ab9e..b8aa91b87 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -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;
diff --git a/src/loadext.c b/src/loadext.c
index 8fe35d9fa..835b8a84e 100644
--- a/src/loadext.c
+++ b/src/loadext.c
@@ -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);
}
diff --git a/src/malloc.c b/src/malloc.c
index 05ea51006..73508bdef 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -368,6 +368,7 @@ void sqlite3ScratchFree(void *p){
|| p<sqlite3GlobalConfig.pScratch
|| p>=(void*)mem0.aScratchFree ){
assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
+ assert( sqlite3MemdebugNoType(p, ~MEMTYPE_SCRATCH) );
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
if( sqlite3GlobalConfig.bMemstat ){
int iSize = sqlite3MallocSize(p);
@@ -408,7 +409,7 @@ void sqlite3ScratchFree(void *p){
*/
#ifndef SQLITE_OMIT_LOOKASIDE
static int isLookaside(sqlite3 *db, void *p){
- return db && p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
+ return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd;
}
#else
#define isLookaside(A,B) 0
@@ -420,15 +421,17 @@ static int isLookaside(sqlite3 *db, void *p){
*/
int sqlite3MallocSize(void *p){
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
+ assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
return sqlite3GlobalConfig.m.xSize(p);
}
int sqlite3DbMallocSize(sqlite3 *db, void *p){
assert( db==0 || sqlite3_mutex_held(db->mutex) );
- if( isLookaside(db, p) ){
+ if( db && isLookaside(db, p) ){
return db->lookaside.sz;
}else{
- assert( sqlite3MemdebugHasType(p,
- db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
+ assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
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( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
if( sqlite3GlobalConfig.bMemstat ){
sqlite3_mutex_enter(mem0.mutex);
@@ -455,23 +459,24 @@ void sqlite3_free(void *p){
*/
void sqlite3DbFree(sqlite3 *db, void *p){
assert( db==0 || sqlite3_mutex_held(db->mutex) );
- if( db && db->pnBytesFreed ){
+ if( db ){
+ if( db->pnBytesFreed ){
+ *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
+ return;
+ }
if( isLookaside(db, p) ){
- *db->pnBytesFreed += db->lookaside.sz;
- }else{
- *db->pnBytesFreed += sqlite3MallocSize(p);
+ LookasideSlot *pBuf = (LookasideSlot*)p;
+ pBuf->pNext = db->lookaside.pFree;
+ db->lookaside.pFree = pBuf;
+ db->lookaside.nOut--;
+ return;
}
- }else if( isLookaside(db, p) ){
- LookasideSlot *pBuf = (LookasideSlot*)p;
- pBuf->pNext = db->lookaside.pFree;
- db->lookaside.pFree = pBuf;
- db->lookaside.nOut--;
- }else{
- assert( sqlite3MemdebugHasType(p,
- db ? (MEMTYPE_DB|MEMTYPE_HEAP) : MEMTYPE_HEAP) );
- sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
- sqlite3_free(p);
}
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
+ assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
+ sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
+ sqlite3_free(p);
}
/*
@@ -503,6 +508,7 @@ void *sqlite3Realloc(void *pOld, int nBytes){
sqlite3MallocAlarm(nNew-nOld);
}
assert( sqlite3MemdebugHasType(pOld, MEMTYPE_HEAP) );
+ assert( sqlite3MemdebugNoType(pOld, ~MEMTYPE_HEAP) );
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
if( pNew==0 && mem0.alarmCallback ){
sqlite3MallocAlarm(nBytes);
@@ -600,8 +606,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_DB |
+ ((db && db->lookaside.bEnabled) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
return p;
}
@@ -627,14 +633,16 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
sqlite3DbFree(db, p);
}
}else{
- assert( sqlite3MemdebugHasType(p, MEMTYPE_DB|MEMTYPE_HEAP) );
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) );
+ assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) );
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
pNew = sqlite3_realloc(p, n);
if( !pNew ){
+ sqlite3MemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP);
db->mallocFailed = 1;
}
- sqlite3MemdebugSetType(pNew,
- db->lookaside.bEnabled ? MEMTYPE_DB : MEMTYPE_HEAP);
+ sqlite3MemdebugSetType(pNew, MEMTYPE_DB |
+ (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP));
}
}
return pNew;
diff --git a/src/mem2.c b/src/mem2.c
index a82fee8fd..528a020f5 100644
--- a/src/mem2.c
+++ b/src/mem2.c
@@ -401,19 +401,34 @@ 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;
}
}
return rc;
}
-
+
+/*
+** Return TRUE if the mask of type in eType matches no bits of the type of the
+** allocation p. Also return true if p==NULL.
+**
+** This routine is designed for use within an assert() statement, to
+** verify the type of an allocation. For example:
+**
+** assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) );
+*/
+int sqlite3MemdebugNoType(void *p, u8 eType){
+ int rc = 1;
+ if( p ){
+ struct MemBlockHdr *pHdr;
+ pHdr = sqlite3MemsysGetHeader(p);
+ assert( pHdr->iForeGuard==FOREGUARD ); /* Allocation is valid */
+ if( (pHdr->eType&eType)!=0 ){
+ rc = 0;
+ }
+ }
+ return rc;
+}
/*
** Set the number of backtrace levels kept for each allocation.
diff --git a/src/notify.c b/src/notify.c
index 4c8ab0077..fcab5bfaf 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -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);
diff --git a/src/pragma.c b/src/pragma.c
index 242896518..0f3ce3c52 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -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;
}
diff --git a/src/printf.c b/src/printf.c
index 6ab230b88..da2fdf610 100644
--- a/src/printf.c
+++ b/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;
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 66f1cffb5..02705769c 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2327,7 +2327,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 */
};
@@ -3120,17 +3120,18 @@ SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...);
** sqlite3MemdebugHasType() returns true if any of the bits in its second
** argument match the type set by the previous sqlite3MemdebugSetType().
** sqlite3MemdebugHasType() is intended for use inside assert() statements.
-** For example:
**
-** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) );
+** sqlite3MemdebugNoType() returns true if none of the bits in its second
+** argument match the type set by the previous sqlite3MemdebugSetType().
**
** Perhaps the most important point is the difference between MEMTYPE_HEAP
-** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have
-** been allocated by lookaside, except the allocation was too large or
-** lookaside was already full. It is important to verify that allocations
-** that might have been satisfied by lookaside are not passed back to
-** non-lookaside free() routines. Asserts such as the example above are
-** placed on the non-lookaside free() routines to verify this constraint.
+** and MEMTYPE_LOOKASIDE. If an allocation is MEMTYPE_LOOKASIDE, that means
+** it might have been allocated by lookaside, except the allocation was
+** too large or lookaside was already full. It is important to verify
+** that allocations that might have been satisfied by lookaside are not
+** passed back to non-lookaside free() routines. Asserts such as the
+** example above are placed on the non-lookaside free() routines to verify
+** this constraint.
**
** All of this is no-op for a production build. It only comes into
** play when the SQLITE_MEMDEBUG compile-time option is used.
@@ -3138,13 +3139,16 @@ SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...);
#ifdef SQLITE_MEMDEBUG
void sqlite3MemdebugSetType(void*,u8);
int sqlite3MemdebugHasType(void*,u8);
+ int sqlite3MemdebugNoType(void*,u8);
#else
# define sqlite3MemdebugSetType(X,Y) /* no-op */
# define sqlite3MemdebugHasType(X,Y) 1
+# define sqlite3MemdebugNoType(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_LOOKASIDE 0x02 /* Might have been lookaside memory */
+#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
+#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
+#define MEMTYPE_DB 0x10 /* Uses sqlite3DbMalloc, not sqlite_malloc */
#endif /* _SQLITEINT_H_ */
diff --git a/src/test4.c b/src/test4.c
index cb5087bef..49447d351 100644
--- a/src/test4.c
+++ b/src/test4.c
@@ -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;
}
diff --git a/src/test5.c b/src/test5.c
index dc7dafe75..504fdb8a9 100644
--- a/src/test5.c
+++ b/src/test5.c
@@ -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{
diff --git a/src/test7.c b/src/test7.c
index 77b36610b..3383d868d 100644
--- a/src/test7.c
+++ b/src/test7.c
@@ -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;
}
diff --git a/src/test8.c b/src/test8.c
index 110aa6561..b3e6058ac 100644
--- a/src/test8.c
+++ b/src/test8.c
@@ -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));
}
}
diff --git a/src/tokenize.c b/src/tokenize.c
index e8778e69a..c624efdcc 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -496,7 +496,7 @@ abort_parse:
}
#endif
#ifndef SQLITE_OMIT_VIRTUALTABLE
- sqlite3DbFree(db, pParse->apVtabLock);
+ sqlite3_free(pParse->apVtabLock);
#endif
if( !IN_DECLARE_VTAB ){
diff --git a/src/vdbe.c b/src/vdbe.c
index 6813837d2..29c2d498d 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -502,6 +502,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.
**
** sqlite3VdbeMakeReady() must be called before this routine in order to
@@ -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;
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index a297ddd8d..7359d18ab 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -584,7 +584,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:
@@ -592,6 +591,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);
@@ -756,7 +759,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;
diff --git a/src/vtab.c b/src/vtab.c
index e57f4e480..bd4cf441f 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -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;
diff --git a/src/where.c b/src/where.c
index 3e6189c57..e527fbd6f 100644
--- a/src/where.c
+++ b/src/where.c
@@ -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++){