From 4150ebf86fd9935a19dbdc67bdd72e45a1d46a13 Mon Sep 17 00:00:00 2001 From: drh Date: Sat, 11 Oct 2008 15:38:29 +0000 Subject: [PATCH] Added an assert() to detect lookaside memory leaks. Also added the SQLITE_OMIT_LOOKASIDE compile-time option which is useful in trying to track down lookaside memory leaks. (CVS 5800) FossilOrigin-Name: 0c4c66071a46cecc5f87afb8f8f01ae2c90ee9b3 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/main.c | 3 ++- src/malloc.c | 8 +++++++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 672c65dc2b..72d5125511 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sassertion\sfault\sthat\soccurs\swith\sSQLITE_THREADSAFE=0.\s(CVS\s5799) -D 2008-10-11T15:20:05 +C Added\san\sassert()\sto\sdetect\slookaside\smemory\sleaks.\s\sAlso\sadded\sthe\nSQLITE_OMIT_LOOKASIDE\scompile-time\soption\swhich\sis\suseful\sin\strying\sto\ntrack\sdown\slookaside\smemory\sleaks.\s(CVS\s5800) +D 2008-10-11T15:38:30 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 7fc26e087207e7a4a7723583dbd7997477af3b13 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -118,8 +118,8 @@ F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3 F src/loadext.c cadd5df14bcda5ef0c26d815eb609a755861923e -F src/main.c eca6e80598aeccb58f722c2f1c0f25ee6b442c16 -F src/malloc.c 31f4ca218f4b664dce45ef9c4f1fcd2929c67a42 +F src/main.c 479e3b64066ac58d9957795608b0950425877f5f +F src/malloc.c 20613ebf4664dec6eb47f62d76264b24ee2a7e4a F src/mem1.c 5a529ff121c55ab067be14de00f86f6dcc4f4fb9 F src/mem2.c f87e681d0d1ed8436870d089332ed0d27d885b5c F src/mem3.c 1594f117fde4cf11a6c16521f3f30af8d04bbe68 @@ -648,7 +648,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P fab4940d54fd1e5459a3d0d9b64b491e6972fd8d -R 8cb8a1748def7de0b4ac00aa033b0078 +P 28bba42b338afd63e1dad9f431d631f6f3027275 +R 74f64a08ff5ef738b9c92d4ed58f474f U drh -Z 6d1bf3ab78bfeca6642c5036493454fe +Z 24abcbe1839acd523ab8a8985b39233b diff --git a/manifest.uuid b/manifest.uuid index dd147cc9b4..2a53e8939f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -28bba42b338afd63e1dad9f431d631f6f3027275 \ No newline at end of file +0c4c66071a46cecc5f87afb8f8f01ae2c90ee9b3 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 97d5475c71..1e6d2d5bf0 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.506 2008/10/11 15:20:05 drh Exp $ +** $Id: main.c,v 1.507 2008/10/11 15:38:30 drh Exp $ */ #include "sqliteInt.h" #include @@ -635,6 +635,7 @@ int sqlite3_close(sqlite3 *db){ sqlite3_mutex_leave(db->mutex); db->magic = SQLITE_MAGIC_CLOSED; sqlite3_mutex_free(db->mutex); + assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */ if( db->lookaside.bMalloced ){ sqlite3_free(db->lookaside.pStart); } diff --git a/src/malloc.c b/src/malloc.c index 65fdc26d0f..2d09af68ae 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.42 2008/09/23 16:41:30 danielk1977 Exp $ +** $Id: malloc.c,v 1.43 2008/10/11 15:38:30 drh Exp $ */ #include "sqliteInt.h" #include @@ -485,9 +485,13 @@ void sqlite3PageFree(void *p){ /* ** TRUE if p is a lookaside memory allocation from db */ +#ifndef SQLITE_OMIT_LOOKASIDE static int isLookaside(sqlite3 *db, void *p){ return db && p && p>=db->lookaside.pStart && plookaside.pEnd; } +#else +#define isLookaside(A,B) 0 +#endif /* ** Return the size of a memory allocation previously obtained from @@ -617,6 +621,7 @@ void *sqlite3DbMallocZero(sqlite3 *db, int n){ */ void *sqlite3DbMallocRaw(sqlite3 *db, int n){ void *p; +#ifndef SQLITE_OMIT_LOOKASIDE if( db ){ LookasideSlot *pBuf; if( db->mallocFailed ){ @@ -632,6 +637,7 @@ void *sqlite3DbMallocRaw(sqlite3 *db, int n){ return (void*)pBuf; } } +#endif p = sqlite3Malloc(n); if( !p && db ){ db->mallocFailed = 1; -- 2.47.2