aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan <dan@noemail.net>2014-10-15 19:37:13 +0000
committerdan <dan@noemail.net>2014-10-15 19:37:13 +0000
commitf11b256b0bad2e843f4df0205bd7093f632aa38d (patch)
treebe608b0913db6a27e576bd58c4e07e73abf73de7 /src
parent92fe38ece56c01929b8ad949c94a8b7732db496c (diff)
parent5d510d4c412ec360cec5cd088fd8debff94e3354 (diff)
downloadsqlite-f11b256b0bad2e843f4df0205bd7093f632aa38d.tar.gz
sqlite-f11b256b0bad2e843f4df0205bd7093f632aa38d.zip
Merge latest trunk changes with this branch.
FossilOrigin-Name: 1b2824f1d11ac336779372e322aecfb36fb2a31d
Diffstat (limited to 'src')
-rw-r--r--src/btree.c22
-rw-r--r--src/btreeInt.h2
-rw-r--r--src/vdbemem.c2
-rw-r--r--src/vtab.c1
4 files changed, 20 insertions, 7 deletions
diff --git a/src/btree.c b/src/btree.c
index 3553924c0..758dfe633 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -2108,7 +2108,8 @@ static int removeFromSharingList(BtShared *pBt){
/*
** Make sure pBt->pTmpSpace points to an allocation of
-** MX_CELL_SIZE(pBt) bytes.
+** MX_CELL_SIZE(pBt) bytes with a 4-byte prefix for a left-child
+** pointer.
*/
static void allocateTempSpace(BtShared *pBt){
if( !pBt->pTmpSpace ){
@@ -2123,8 +2124,16 @@ static void allocateTempSpace(BtShared *pBt){
** it into a database page. This is not actually a problem, but it
** does cause a valgrind error when the 1 or 2 bytes of unitialized
** data is passed to system call write(). So to avoid this error,
- ** zero the first 4 bytes of temp space here. */
- if( pBt->pTmpSpace ) memset(pBt->pTmpSpace, 0, 4);
+ ** zero the first 4 bytes of temp space here.
+ **
+ ** Also: Provide four bytes of initialized space before the
+ ** beginning of pTmpSpace as an area available to prepend the
+ ** left-child pointer to the beginning of a cell.
+ */
+ if( pBt->pTmpSpace ){
+ memset(pBt->pTmpSpace, 0, 8);
+ pBt->pTmpSpace += 4;
+ }
}
}
@@ -2132,8 +2141,11 @@ static void allocateTempSpace(BtShared *pBt){
** Free the pBt->pTmpSpace allocation
*/
static void freeTempSpace(BtShared *pBt){
- sqlite3PageFree( pBt->pTmpSpace);
- pBt->pTmpSpace = 0;
+ if( pBt->pTmpSpace ){
+ pBt->pTmpSpace -= 4;
+ sqlite3PageFree(pBt->pTmpSpace);
+ pBt->pTmpSpace = 0;
+ }
}
/*
diff --git a/src/btreeInt.h b/src/btreeInt.h
index 9f648fceb..2368e6c88 100644
--- a/src/btreeInt.h
+++ b/src/btreeInt.h
@@ -436,7 +436,7 @@ struct BtShared {
BtLock *pLock; /* List of locks held on this shared-btree struct */
Btree *pWriter; /* Btree with currently open write transaction */
#endif
- u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
+ u8 *pTmpSpace; /* Temp space sufficient to hold a single cell */
};
/*
diff --git a/src/vdbemem.c b/src/vdbemem.c
index 37d92aca1..db527327e 100644
--- a/src/vdbemem.c
+++ b/src/vdbemem.c
@@ -143,7 +143,7 @@ SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
}
}
- if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){
+ if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
memcpy(pMem->zMalloc, pMem->z, pMem->n);
}
if( (pMem->flags&MEM_Dyn)!=0 ){
diff --git a/src/vtab.c b/src/vtab.c
index c7a8a5a33..faee4ae47 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -519,6 +519,7 @@ static int vtabCallConstructor(
}else if( ALWAYS(pVTable->pVtab) ){
/* Justification of ALWAYS(): A correct vtab constructor must allocate
** the sqlite3_vtab object if successful. */
+ memset(pVTable->pVtab, 0, sizeof(pVTable->pVtab[0]));
pVTable->pVtab->pModule = pMod->pModule;
pVTable->nRef = 1;
if( sCtx.pTab ){