From: dan Date: Sat, 29 Mar 2014 09:34:45 +0000 (+0000) Subject: Fix a problem in vdbesort.c causing spurious SQLITE_NOMEM errors when using memsys3... X-Git-Tag: version-3.8.7~132^2~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e7c84cc7e30a90fdefc8508b5ef6fc2bed48e115;p=thirdparty%2Fsqlite.git Fix a problem in vdbesort.c causing spurious SQLITE_NOMEM errors when using memsys3 or memsys5. FossilOrigin-Name: a683c05f6250389e84b980b16559e162ba1a27c2 --- diff --git a/manifest b/manifest index a8a84cabb7..5859cf8e2e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\soptimization\sto\savoid\ssome\sunnecessary\scalls\sto\ssqlite3VdbeRecordUnpack()\sadded\sto\sthe\strunk\sby\s[707ea170b3]. -D 2014-03-29T06:27:35.162 +C Fix\sa\sproblem\sin\svdbesort.c\scausing\sspurious\sSQLITE_NOMEM\serrors\swhen\susing\smemsys3\sor\smemsys5. +D 2014-03-29T09:34:45.457 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in ad0921c4b2780d01868cf69b419a4f102308d125 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -286,7 +286,7 @@ F src/vdbeapi.c 0ed6053f947edd0b30f64ce5aeb811872a3450a4 F src/vdbeaux.c 1153175fb57a8454e1c8cf79b59b7bf92b26779d F src/vdbeblob.c 15377abfb59251bccedd5a9c7d014a895f0c04aa F src/vdbemem.c 6fc77594c60f6155404f3f8d71bf36d1fdeb4447 -F src/vdbesort.c d7ef3c431d7996907815a13579952506bf2bdf8b +F src/vdbesort.c 80812ceb596febe778d506587d24bef6fabc00d4 F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767 F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8 @@ -1160,7 +1160,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 4c7fb5423430f3b936befaa7c309f8e1968ee7d8 -R c555f8c440b397229a1b1d80867cea18 +P fc4d04e6b039ea5aeb47739e38c5926e63a4b01b +R 58d9f269ef794b7845b0943176283ea0 U dan -Z 5b7820939497d4f0728d4d29380b4189 +Z 849635fb9198ef253e10fe8fcdddee0e diff --git a/manifest.uuid b/manifest.uuid index d7c0207d3a..0e4e18ad35 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fc4d04e6b039ea5aeb47739e38c5926e63a4b01b \ No newline at end of file +a683c05f6250389e84b980b16559e162ba1a27c2 \ No newline at end of file diff --git a/src/vdbesort.c b/src/vdbesort.c index e6fbbdd2df..d9c26f209e 100644 --- a/src/vdbesort.c +++ b/src/vdbesort.c @@ -1046,7 +1046,6 @@ static int vdbeSorterNext( ){ int rc; int iPrev = pMerger->aTree[1];/* Index of iterator to advance */ - int i; /* Index of aTree[] to recalculate */ /* Advance the current iterator */ rc = vdbeSorterIterNext(&pMerger->aIter[iPrev]); @@ -1281,11 +1280,14 @@ static int vdbeSorterFlushPMA(sqlite3 *db, const VdbeCursor *pCsr, int bFg){ if( bUseFg==0 ){ /* Launch a background thread for this operation */ void *pCtx = (void*)pThread; - if( pSorter->aMemory==0 ){ - pSorter->aMemory = sqlite3Malloc(pSorter->nMemory); - if( pSorter->aMemory==0 ) return SQLITE_NOMEM; - }else{ - pSorter->nMemory = sqlite3MallocSize(pSorter->aMemory); + assert( pSorter->aMemory==0 || pThread->aListMemory==0 ); + if( pThread->aListMemory ){ + if( pSorter->aMemory==0 ){ + pSorter->aMemory = sqlite3Malloc(pSorter->nMemory); + if( pSorter->aMemory==0 ) return SQLITE_NOMEM; + }else{ + pSorter->nMemory = sqlite3MallocSize(pSorter->aMemory); + } } rc = sqlite3ThreadCreate(&pThread->pThread, vdbeSorterThreadMain, pCtx); }else{ @@ -1337,19 +1339,21 @@ int sqlite3VdbeSorterWrite( */ nReq = pVal->n + sizeof(SorterRecord); nPMA = pVal->n + sqlite3VarintLen(pVal->n); - if( pSorter->aMemory ){ - bFlush = pSorter->iMemory && (pSorter->iMemory+nReq) > pSorter->mxPmaSize; - }else{ - bFlush = ( - (pSorter->nInMemory > pSorter->mxPmaSize) - || (pSorter->nInMemory > pSorter->mnPmaSize && sqlite3HeapNearlyFull()) - ); - } - if( bFlush ){ - rc = vdbeSorterFlushPMA(db, pCsr, 0); - pSorter->nInMemory = 0; - pSorter->iMemory = 0; - assert( rc!=SQLITE_OK || pSorter->pRecord==0 ); + if( pSorter->mxPmaSize ){ + if( pSorter->aMemory ){ + bFlush = pSorter->iMemory && (pSorter->iMemory+nReq) > pSorter->mxPmaSize; + }else{ + bFlush = ( + (pSorter->nInMemory > pSorter->mxPmaSize) + || (pSorter->nInMemory > pSorter->mnPmaSize && sqlite3HeapNearlyFull()) + ); + } + if( bFlush ){ + rc = vdbeSorterFlushPMA(db, pCsr, 0); + pSorter->nInMemory = 0; + pSorter->iMemory = 0; + assert( rc!=SQLITE_OK || pSorter->pRecord==0 ); + } } pSorter->nInMemory += nPMA; @@ -1375,7 +1379,7 @@ int sqlite3VdbeSorterWrite( pSorter->iMemory += ROUND8(nReq); pNew->u.iNext = (u8*)(pSorter->pRecord) - pSorter->aMemory; }else{ - pNew = (SorterRecord *)sqlite3Malloc(pVal->n+sizeof(SorterRecord)); + pNew = (SorterRecord *)sqlite3Malloc(nReq); if( pNew==0 ){ return SQLITE_NOMEM; }