diff options
author | drh <drh@noemail.net> | 2010-03-12 16:32:53 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2010-03-12 16:32:53 +0000 |
commit | 107b56e86d4de6e5ac1c659a8dab38063e9326d3 (patch) | |
tree | 290df93a9145799a655694a04cdaf68d6312a921 /src/sqliteInt.h | |
parent | 735b9cbb96b56a9f4a44d2b159457b8a6321310e (diff) | |
download | sqlite-107b56e86d4de6e5ac1c659a8dab38063e9326d3.tar.gz sqlite-107b56e86d4de6e5ac1c659a8dab38063e9326d3.zip |
Add assert()s to mem2.c (activated by SQLITE_MEMDEBUG) which verify that
memory alloctions that might have come from lookaside are always freed
using a lookaside-aware free routine.
FossilOrigin-Name: c2af2164cf7b279ebb3e08201561348be6e765df
Diffstat (limited to 'src/sqliteInt.h')
-rw-r--r-- | src/sqliteInt.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a21513d23..c674b71bd 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3089,4 +3089,43 @@ SQLITE_EXTERN void (*sqlite3IoTrace)(const char*,...); # define sqlite3VdbeIOTraceSql(X) #endif +/* +** These routines are available for the mem2.c debugging memory allocator +** only. They are used to verify that different "types" of memory +** allocations are properly tracked by the system. +** +** sqlite3MemdebugSetType() sets the "type" of an allocation to one of +** the MEMTYPE_* macros defined below. The type must be a bitmask with +** a single bit set. +** +** sqlite3MemdebugHasType() returns true if any of the bits in its second +** argument match the type set by the previous sqlite3MemdebugSetType(). +** sqlite3MemdebugHasType() is intended for use inside assert() statements. +** For example: +** +** assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); +** +** Perhaps the most important point is the difference between MEMTYPE_HEAP +** and MEMTYPE_DB. If an allocation is MEMTYPE_DB, that means it might have +** been allocated by lookaside, except the allocation was too large or +** lookaside was already full. It is important to verify that allocations +** that might have been satisfied by lookaside are not passed back to +** non-lookaside free() routines. Asserts such as the example above are +** placed on the non-lookaside free() routines to verify this constraint. +** +** All of this is no-op for a production build. It only comes into +** play when the SQLITE_MEMDEBUG compile-time option is used. +*/ +#ifdef SQLITE_MEMDEBUG + void sqlite3MemdebugSetType(void*,u8); + int sqlite3MemdebugHasType(void*,u8); +#else +# define sqlite3MemdebugSetType(X,Y) /* no-op */ +# define sqlite3MemdebugHasType(X,Y) 1 #endif +#define MEMTYPE_HEAP 0x01 /* General heap allocations */ +#define MEMTYPE_DB 0x02 /* Associated with a database connection */ +#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */ +#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */ + +#endif /* _SQLITEINT_H_ */ |