/* ** This is the test layer's wrapper around sqlite3OsFree(). The argument is a ** pointer to the space allocated for the application to use. */ static void OSFREE(void *pFree){ u32 *p = (u32 *)getOsPointer(pFree); /* p points to Os level allocation */ checkGuards(p); unlinkAlloc(p); memset(pFree, 0x55, OSSIZEOF(pFree)); sqlite3OsFree(p); sqlite3_nFree++; }
/* ** This is the test layer's wrapper around sqlite3OsFree(). The argument is a ** pointer to the space allocated for the application to use. */ static void OSFREE(void *pFree){ u32 *p; /* Pointer to the OS-layer allocation */ sqlite3OsEnterMutex(); p = (u32 *)getOsPointer(pFree); checkGuards(p); unlinkAlloc(p); memset(pFree, 0x55, OSSIZEOF(pFree)); sqlite3OsFree(p); sqlite3_nFree++; sqlite3OsLeaveMutex(); }
/* ** Allocate and return N bytes of uninitialised memory by calling ** sqlite3OsMalloc(). If the Malloc() call fails, attempt to free memory ** by calling sqlite3_release_memory(). */ void *sqlite3MallocRaw(int n, int doMemManage){ void *p = 0; if( n>0 && !sqlite3MallocFailed() && (!doMemManage || enforceSoftLimit(n)) ){ while( (p = OSMALLOC(n))==0 && sqlite3_release_memory(n) ){} if( !p ){ sqlite3FailedMalloc(); OSMALLOC_FAILED(); }else if( doMemManage ){ updateMemoryUsedCount(OSSIZEOF(p)); } } return p; }
/* ** Resize the allocation at p to n bytes by calling sqlite3OsRealloc(). The ** pointer to the new allocation is returned. If the Realloc() call fails, ** attempt to free memory by calling sqlite3_release_memory(). */ void *sqlite3Realloc(void *p, int n){ if( sqlite3MallocFailed() ){ return 0; } if( !p ){ return sqlite3Malloc(n, 1); }else{ void *np = 0; #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT int origSize = OSSIZEOF(p); #endif if( enforceSoftLimit(n - origSize) ){ while( (np = OSREALLOC(p, n))==0 && sqlite3_release_memory(n) ){} if( !np ){ sqlite3FailedMalloc(); OSMALLOC_FAILED(); }else{ updateMemoryUsedCount(OSSIZEOF(np) - origSize); } } return np; } }
int sqlite3AllocSize(void *p){ return OSSIZEOF(p); }
/* ** Free the memory pointed to by p. p must be either a NULL pointer or a ** value returned by a previous call to sqlite3Malloc() or sqlite3Realloc(). */ void sqlite3FreeX(void *p){ if( p ){ updateMemoryUsedCount(0 - OSSIZEOF(p)); OSFREE(p); } }