Avoid attempting to reclaim memory from in-memory databases in sqlite3_release_memory(). (CVS 3812)

FossilOrigin-Name: c20f7563c0ffa1df47df5464f1f1cc4703ffa9b4
This commit is contained in:
danielk1977 2007-04-05 13:12:13 +00:00
parent 5bb16fe41b
commit c551edc2c3
4 changed files with 55 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Add\ssome\sassert()\sstatements\sto\spager.c.\s(CVS\s3811)
D 2007-04-05T11:54:43
C Avoid\sattempting\sto\sreclaim\smemory\sfrom\sin-memory\sdatabases\sin\ssqlite3_release_memory().\s(CVS\s3812)
D 2007-04-05T13:12:14
F Makefile.in 29fbf08ce0989973bfed0b5a052a6bdf3e60fd0a
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -86,7 +86,7 @@ F src/os_unix.c 13c6f73a7b0c2c6c131c97ea26274db101b594cd
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c c9a99524d6b2bdec636264cad1b67553925e3309
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 52f2212429310cb4d2080d36b63d16cc42161a6f
F src/pager.c 82dca058bfb68aa34a3ff330bc9ad466035375ae
F src/pager.h e79a24cf200b8771366217f5bca414f5b7823f42
F src/parse.y 207ab04273ae13aa4a729b96008d294d5f334ab3
F src/pragma.c 3b992b5b2640d6ae25cef05aa6a42cd1d6c43234
@ -263,7 +263,7 @@ F test/malloc.test d868a6b98b07928b00bca3d9874daf6885c86150
F test/malloc2.test 4ed7d719542c4570dec9c2ebe2bbdf3a9f3b0d05
F test/malloc3.test e965954b6f808876a63d3101fd70370320b509a7
F test/malloc4.test 59cd02f71b363302a04c4e77b97c0a1572eaa210
F test/malloc5.test 17a32bd72073741d539bb2a1307d712a316b89da
F test/malloc5.test ab22dcb9f0babc57126f55bfc6a6b6c7dd51c6cc
F test/malloc6.test 025ae0b78542e0ddd000d23f79d93e9be9ba0f15
F test/malloc7.test 1cf52834509eac7ebeb92105dacd4669f9ca9869
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
@ -450,7 +450,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 38af156da83a8469080ddb75a9a286be33ff6bef
R 28d04fcd2d61aa62015dffc325fe3e28
P 973b2a5fb56a1ed1fd10d062edcb6e6dad13f001
R 3d61a3bac9e818ce7c0c533a6c40bb32
U danielk1977
Z df28133608de4a90d3e36cfb35940c5f
Z 27fd82d7f84e6401bc77ed2f6bdb8478

View File

@ -1 +1 @@
973b2a5fb56a1ed1fd10d062edcb6e6dad13f001
c20f7563c0ffa1df47df5464f1f1cc4703ffa9b4

View File

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.320 2007/04/05 11:54:43 danielk1977 Exp $
** @(#) $Id: pager.c,v 1.321 2007/04/05 13:12:14 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@ -2525,6 +2525,8 @@ static int pager_recycle(Pager *pPager, int syncOk, PgHdr **ppPg){
PgHdr *pPg;
*ppPg = 0;
assert(!MEMDB);
/* Find a page to recycle. Try to locate a page that does not
** require us to do an fsync() on the journal.
*/
@ -2568,7 +2570,6 @@ static int pager_recycle(Pager *pPager, int syncOk, PgHdr **ppPg){
if( pPg->dirty ){
int rc;
assert( pPg->needSync==0 );
assert( !MEMDB );
makeClean(pPg);
pPg->dirty = 1;
pPg->pDirty = 0;
@ -2640,6 +2641,12 @@ int sqlite3PagerReleaseMemory(int nReq){
PgHdr *pPg;
int rc;
#ifndef SQLITE_OMIT_MEMORYDB
if( p->memDb ){
continue;
}
#endif
/* For each pager, try to free as many pages as possible (without
** calling fsync() if this is the first iteration of the outermost
** loop).
@ -2842,10 +2849,10 @@ static int pagerAllocatePage(Pager *pPager, PgHdr **ppPg){
int rc = SQLITE_OK;
PgHdr *pPg;
if( !(pPager->pFirstSynced && pPager->pFirstSynced->pgno==0) && (
pPager->nPage<pPager->mxPage || pPager->pFirst==0 || MEMDB ||
if( MEMDB || (!(pPager->pFirstSynced && pPager->pFirstSynced->pgno==0) && (
pPager->nPage<pPager->mxPage || pPager->pFirst==0 ||
(pPager->pFirstSynced==0 && pPager->doNotSync)
) ){
)) ){
/* Create a new page */
if( pPager->nPage>=pPager->nHash ){
pager_resize_hash_table(pPager,

View File

@ -12,7 +12,7 @@
# This file contains test cases focused on the two memory-management APIs,
# sqlite3_soft_heap_limit() and sqlite3_release_memory().
#
# $Id: malloc5.test,v 1.8 2007/04/02 05:07:48 danielk1977 Exp $
# $Id: malloc5.test,v 1.9 2007/04/05 13:12:14 danielk1977 Exp $
#---------------------------------------------------------------------------
# NOTES ON EXPECTED BEHAVIOUR
@ -221,7 +221,40 @@ do_test malloc5-4.3 {
# Restore the soft heap limit.
sqlite3_soft_heap_limit $::soft_limit
finish_test
# Test that there are no problems calling sqlite3_release_memory when
# there are open in-memory databases.
#
# At one point these tests would cause a seg-fault.
#
do_test malloc5-5.1 {
db close
sqlite3 db :memory:
execsql {
BEGIN;
CREATE TABLE abc(a, b, c);
INSERT INTO abc VALUES('abcdefghi', 1234567890, NULL);
INSERT INTO abc SELECT * FROM abc;
INSERT INTO abc SELECT * FROM abc;
INSERT INTO abc SELECT * FROM abc;
INSERT INTO abc SELECT * FROM abc;
INSERT INTO abc SELECT * FROM abc;
INSERT INTO abc SELECT * FROM abc;
INSERT INTO abc SELECT * FROM abc;
}
sqlite3_release_memory
} 0
do_test malloc5-5.1 {
sqlite3_soft_heap_limit 5000
execsql {
COMMIT;
PRAGMA temp_store = memory;
SELECT * FROM abc ORDER BY a;
}
expr 1
} {1}
sqlite3_soft_heap_limit $::soft_limit
finish_test
catch {db close}