mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Add the test_oom_breakpoint() routine on debug builds, to serve as a
convenient breakpoint to intercept OOM conditions. FossilOrigin-Name: e45df7dcd6b5766d7593ee87e59dd422a217cce0a1a8d369c03144bb21859428
This commit is contained in:
20
src/malloc.c
20
src/malloc.c
@@ -221,6 +221,24 @@ static void sqlite3MallocAlarm(int nByte){
|
||||
sqlite3_mutex_enter(mem0.mutex);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
/*
|
||||
** This routine is called whenever an out-of-memory condition is seen,
|
||||
** It's only purpose to to serve as a breakpoint for gdb or similar
|
||||
** code debuggers when working on out-of-memory conditions, for example
|
||||
** caused by PRAGMA hard_heap_limit=N.
|
||||
*/
|
||||
static SQLITE_NOINLINE void test_oom_breakpoint(void){
|
||||
static u64 nOomFault = 0;
|
||||
nOomFault++;
|
||||
/* The assert() is never reached in a human lifetime. It is here mostly
|
||||
** to prevent code optimizers from optimizing out this function. */
|
||||
assert( (nOomFault>>32) < 0xffffffff );
|
||||
}
|
||||
#else
|
||||
# define test_oom_breakpoint(X) /* No-op for production builds */
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Do a memory allocation with statistics and alarms. Assume the
|
||||
** lock is already held.
|
||||
@@ -247,6 +265,7 @@ static void mallocWithAlarm(int n, void **pp){
|
||||
if( mem0.hardLimit ){
|
||||
nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
|
||||
if( nUsed >= mem0.hardLimit - nFull ){
|
||||
test_oom_breakpoint();
|
||||
*pp = 0;
|
||||
return;
|
||||
}
|
||||
@@ -535,6 +554,7 @@ void *sqlite3Realloc(void *pOld, u64 nBytes){
|
||||
sqlite3MallocAlarm(nDiff);
|
||||
if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){
|
||||
sqlite3_mutex_leave(mem0.mutex);
|
||||
test_oom_breakpoint();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user