diff options
author | drh <> | 2024-08-27 13:57:43 +0000 |
---|---|---|
committer | drh <> | 2024-08-27 13:57:43 +0000 |
commit | fcd65efcf10957ef84cccf0f2bd9381b69dd6dde (patch) | |
tree | a7e2f567f27186780dd500f8bfe0cf295fd9ffef /src/malloc.c | |
parent | 3a39c44c21a801927f98aa3cdb2240f00e701b8a (diff) | |
parent | c013fa50db60dad905aff1c2202edfa7223bdd67 (diff) | |
download | sqlite-fcd65efcf10957ef84cccf0f2bd9381b69dd6dde.tar.gz sqlite-fcd65efcf10957ef84cccf0f2bd9381b69dd6dde.zip |
Merge all the latests trunk enhancements into the win-dupe-crt-fio branch.
FossilOrigin-Name: 2d52db98f47fbcda0622c034b21c2fb19bf4345b88c5c565ae9e6f7128642e43
Diffstat (limited to 'src/malloc.c')
-rw-r--r-- | src/malloc.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/malloc.c b/src/malloc.c index 356750682..9a635e716 100644 --- a/src/malloc.c +++ b/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(u64 n){ + static u64 nOomFault = 0; + nOomFault += n; + /* 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(1); *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(1); return 0; } } |