aboutsummaryrefslogtreecommitdiff
path: root/src/malloc.c
diff options
context:
space:
mode:
authordrh <>2024-02-01 11:38:58 +0000
committerdrh <>2024-02-01 11:38:58 +0000
commitd87299cece175fe92418a8f3a11d14dd56cd9e6a (patch)
tree1f0e5abf46ee327ffe8eff917a1dd775c7306d16 /src/malloc.c
parented0a614c213dcad22d23d9c9c9872933c2e8b68c (diff)
downloadsqlite-d87299cece175fe92418a8f3a11d14dd56cd9e6a.tar.gz
sqlite-d87299cece175fe92418a8f3a11d14dd56cd9e6a.zip
Add the test_oom_breakpoint() routine on debug builds, to serve as a
convenient breakpoint to intercept OOM conditions. FossilOrigin-Name: e45df7dcd6b5766d7593ee87e59dd422a217cce0a1a8d369c03144bb21859428
Diffstat (limited to 'src/malloc.c')
-rw-r--r--src/malloc.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/malloc.c b/src/malloc.c
index 356750682..ef7d2e1ed 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(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;
}
}