Add the ability to simulate out-of-memory errors when using the default

memory allocator, mem1.c.  Fix a bug that this enhancement revealed. (CVS 4875)

FossilOrigin-Name: d55a5e1c11ef90534abd2e5f18d06dd4739ade70
This commit is contained in:
drh 2008-03-18 00:07:10 +00:00
parent 0e8ebe5168
commit 5efaf07099
6 changed files with 38 additions and 33 deletions

View File

@ -1,5 +1,5 @@
C Version\s3.5.7\s(CVS\s4874)
D 2008-03-17T19:03:04
C Add\sthe\sability\sto\ssimulate\sout-of-memory\serrors\swhen\susing\sthe\sdefault\nmemory\sallocator,\smem1.c.\s\sFix\sa\sbug\sthat\sthis\senhancement\srevealed.\s(CVS\s4875)
D 2008-03-18T00:07:11
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 5be94fea84f1599672e5041de03b97990baca593
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -108,7 +108,7 @@ F src/loadext.c eceaebcff9807519ed9494056648d0d879f93ed3
F src/main.c 15db7dda6703f9a41a70337466215bf1a0e1fdcf
F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 62a821702d3292809ca78e7c55c3ca04b05a3757
F src/mem1.c fc716ff521b6dd3e43eaa211967383308800e70a
F src/mem2.c a17fd71f39e593f46445282c36077231e70a31eb
F src/mem3.c 52547678a2ae50c203d54be1a5bf51eb02438a3f
F src/mem4.c 45c328ec6dcb7e8d319cb383615b5fe547ca5409
@ -161,7 +161,7 @@ F src/test_config.c 9223ff4a7b8b97c9d12965b0123db1cbd6757efb
F src/test_devsym.c cee1aecaa90c895030399ca4ae38f84a08038f8a
F src/test_hexio.c 1a1cd8324d57585ea86b922f609fa1fbaaf9662d
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_malloc.c 85e702341c752810017c94c40f2a1ac92128abc0
F src/test_malloc.c cdad54dc6a4152ba2681073cb21f74e76da95551
F src/test_md5.c c107c96637123239c3518b5fbe97a79130f4d32e
F src/test_onefile.c 2fea6d22f13f5f286356c80c77ffd41f995f2b7a
F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f
@ -181,7 +181,7 @@ F src/vdbeapi.c cf9fc963efae3cdf5de08e2a9718b487059c7fc5
F src/vdbeaux.c 83e34e38706889a16fbd77fce3777390d425af79
F src/vdbeblob.c 63c750acc7b5012479f508c0e9627372a82cb65d
F src/vdbefifo.c a30c237b2a3577e1415fb6e288cbb6b8ed1e5736
F src/vdbemem.c 7a39ad5579e0a9e7305a8fe9a2095840f0ab8454
F src/vdbemem.c eca1f7ae77f5de66cd6809800d98f6a9186e0f47
F src/vtab.c 00cd16317b29495c185ff40e4b227917d5a371b2
F src/where.c 78d6689d7154d8d41c1a913e17bce9a320981653
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@ -389,7 +389,7 @@ F test/mallocD.test f78c295e8e18ea3029e65ca08278690e00c22100
F test/mallocE.test db1ed69d7eded1b080952e2a7c37f364ad241b08
F test/mallocF.test 2d5c590ebc2fc7f0dcebdf5aa8498b9aed69107e
F test/mallocG.test b295dc03b6d8d705ce425ff4d1ce6bbeb1c5ab33
F test/malloc_common.tcl bb48df8df8c3ae75a9cb2d3626d54202b2ba2401
F test/malloc_common.tcl 5f7b853b2203bd61c9e3c504d461bc3202d13972
F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
@ -623,7 +623,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P fcf3d0a3d5d3a71155ab0aa5f533da72063d54f0
R 1dda9680613a1b8479a4668dc28f14c0
P 9a6583d375a1b922e88eed888e54e51cbc85f400
R 31d912fc5305f78d6110f0f1f2963749
U drh
Z fbb5cb4a11e45c4a408698a49a0c8107
Z 80b52909a8b7e1801c400c7055de8bb6

View File

@ -1 +1 @@
9a6583d375a1b922e88eed888e54e51cbc85f400
d55a5e1c11ef90534abd2e5f18d06dd4739ade70

View File

@ -12,7 +12,7 @@
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** $Id: mem1.c,v 1.16 2008/02/14 23:26:56 drh Exp $
** $Id: mem1.c,v 1.17 2008/03/18 00:07:11 drh Exp $
*/
#include "sqliteInt.h"
@ -137,10 +137,14 @@ void *sqlite3_malloc(int nBytes){
if( mem.alarmCallback!=0 && mem.nowUsed+nBytes>=mem.alarmThreshold ){
sqlite3MemsysAlarm(nBytes);
}
p = malloc(nBytes+8);
if( p==0 ){
sqlite3MemsysAlarm(nBytes);
if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){
p = 0;
}else{
p = malloc(nBytes+8);
if( p==0 ){
sqlite3MemsysAlarm(nBytes);
p = malloc(nBytes+8);
}
}
if( p ){
p[0] = nBytes;
@ -205,12 +209,16 @@ void *sqlite3_realloc(void *pPrior, int nBytes){
if( mem.nowUsed+nBytes-nOld>=mem.alarmThreshold ){
sqlite3MemsysAlarm(nBytes-nOld);
}
p = realloc(p, nBytes+8);
if( p==0 ){
sqlite3MemsysAlarm(nBytes);
p = pPrior;
p--;
if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){
p = 0;
}else{
p = realloc(p, nBytes+8);
if( p==0 ){
sqlite3MemsysAlarm(nBytes);
p = pPrior;
p--;
p = realloc(p, nBytes+8);
}
}
if( p ){
p[0] = nBytes;

View File

@ -13,7 +13,7 @@
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
** $Id: test_malloc.c,v 1.15 2008/02/19 15:15:16 drh Exp $
** $Id: test_malloc.c,v 1.16 2008/03/18 00:07:11 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -463,18 +463,14 @@ static int test_memdebug_pending(
int objc,
Tcl_Obj *CONST objv[]
){
int nPending;
if( objc!=1 ){
Tcl_WrongNumArgs(interp, 1, objv, "");
return TCL_ERROR;
}
#if defined(SQLITE_MEMDEBUG) || defined(SQLITE_POW2_MEMORY_SIZE)
{
int nPending = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_PENDING,
SQLITE_FAULTINJECTOR_MALLOC);
Tcl_SetObjResult(interp, Tcl_NewIntObj(nPending));
}
#endif
nPending = sqlite3_test_control(SQLITE_TESTCTRL_FAULT_PENDING,
SQLITE_FAULTINJECTOR_MALLOC);
Tcl_SetObjResult(interp, Tcl_NewIntObj(nPending));
return TCL_OK;
}

View File

@ -81,7 +81,7 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
|| (f & (MEM_Dyn|MEM_Static|MEM_Ephem))==MEM_Static
);
if( ((f&MEM_Dyn)==0 || pMem->xDel || sqlite3MallocSize(pMem->z)<n) ){
if( (f&MEM_Dyn)==0 || pMem->xDel || sqlite3MallocSize(pMem->z)<n ){
/* Allocate the new buffer. The minimum allocation size is 32 bytes. */
char *z = 0;
@ -94,6 +94,7 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){
z = sqlite3DbMallocRaw(pMem->db, (n>32?n:32));
}
if( !z ){
pMem->flags = MEM_Null;
return SQLITE_NOMEM;
}
}

View File

@ -12,15 +12,15 @@
# This file contains common code used by many different malloc tests
# within the test suite.
#
# $Id: malloc_common.tcl,v 1.13 2008/02/18 22:24:58 drh Exp $
# $Id: malloc_common.tcl,v 1.14 2008/03/18 00:07:11 drh Exp $
# If we did not compile with malloc testing enabled, then do nothing.
#
ifcapable !memdebug&&!mem5 {
ifcapable faultinjector {
set MEMDEBUG 1
} else {
set MEMDEBUG 0
return 0
} else {
set MEMDEBUG 1
}
# Usage: do_malloc_test <test number> <options...>