mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Always invoke the xRoundup() method of the memory allocator before calling
xMalloc(). FossilOrigin-Name: 77b470b0df73dc5ae5ad2f0170ef7c50558c7c88
This commit is contained in:
16
src/malloc.c
16
src/malloc.c
@@ -219,12 +219,20 @@ static void sqlite3MallocAlarm(int nByte){
|
||||
*/
|
||||
static void mallocWithAlarm(int n, void **pp){
|
||||
void *p;
|
||||
int nFull = 0;
|
||||
int nFull;
|
||||
assert( sqlite3_mutex_held(mem0.mutex) );
|
||||
assert( n>0 );
|
||||
|
||||
/* In Firefox (circa 2017-02-08), xRoundup is remapped to an internal
|
||||
** implementation of malloc_good_size(), which must be called in debug
|
||||
** mode and specifically when the DMD "Dark Matter Detector" is enabled
|
||||
** or else a crash results. Hence, do not attempt to optimization out
|
||||
** the following xRoundup() call. */
|
||||
nFull = sqlite3GlobalConfig.m.xRoundup(n);
|
||||
|
||||
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
|
||||
if( mem0.alarmThreshold>0 ){
|
||||
sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
|
||||
nFull = sqlite3GlobalConfig.m.xRoundup(n);
|
||||
if( nUsed >= mem0.alarmThreshold - nFull ){
|
||||
mem0.nearlyFull = 1;
|
||||
sqlite3MallocAlarm(nFull);
|
||||
@@ -232,11 +240,11 @@ static void mallocWithAlarm(int n, void **pp){
|
||||
mem0.nearlyFull = 0;
|
||||
}
|
||||
}
|
||||
p = sqlite3GlobalConfig.m.xMalloc(n);
|
||||
p = sqlite3GlobalConfig.m.xMalloc(nFull);
|
||||
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
||||
if( p==0 && mem0.alarmThreshold>0 ){
|
||||
sqlite3MallocAlarm(nFull);
|
||||
p = sqlite3GlobalConfig.m.xMalloc(n);
|
||||
p = sqlite3GlobalConfig.m.xMalloc(nFull);
|
||||
}
|
||||
#endif
|
||||
if( p ){
|
||||
|
Reference in New Issue
Block a user