aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2008-03-28 07:42:53 +0000
committerdanielk1977 <danielk1977@noemail.net>2008-03-28 07:42:53 +0000
commitdbdc4d49cbf81aaadfa43f9bb84582f467473aa0 (patch)
tree2eeab02a79f54e9960173b71bfd217e1bc1e96b9 /src
parent19db935225bc66eafbc830e3a76262a0d68d870a (diff)
downloadsqlite-dbdc4d49cbf81aaadfa43f9bb84582f467473aa0.tar.gz
sqlite-dbdc4d49cbf81aaadfa43f9bb84582f467473aa0.zip
If memory is leaked when running a test script with the --malloctrace option, write out a file called leaks.sql in the same format as mallocs.sql containing th e leaked applications. The same tools can then be used to examine the stack traces associated with leaked allocations. (CVS 4926)
FossilOrigin-Name: f1b97ed93183378ff56b4fe7ae8ea269c24092fc
Diffstat (limited to 'src')
-rw-r--r--src/mem2.c11
-rw-r--r--src/test_malloc.c45
2 files changed, 40 insertions, 16 deletions
diff --git a/src/mem2.c b/src/mem2.c
index 56da91462..bacc713f2 100644
--- a/src/mem2.c
+++ b/src/mem2.c
@@ -12,7 +12,7 @@
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
-** $Id: mem2.c,v 1.23 2008/03/21 14:22:44 danielk1977 Exp $
+** $Id: mem2.c,v 1.24 2008/03/28 07:42:54 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -410,6 +410,15 @@ void sqlite3MemdebugSettitle(const char *zTitle){
sqlite3_mutex_leave(mem.mutex);
}
+void sqlite3MemdebugSync(){
+ struct MemBlockHdr *pHdr;
+ for(pHdr=mem.pFirst; pHdr; pHdr=pHdr->pNext){
+ void **pBt = (void**)pHdr;
+ pBt -= pHdr->nBacktraceSlots;
+ mem.xBacktrace(pHdr->iSize, pHdr->nBacktrace-1, &pBt[1]);
+ }
+}
+
/*
** Open the file indicated and write a log of all unfreed memory
** allocations into that log.
diff --git a/src/test_malloc.c b/src/test_malloc.c
index 3595a0651..09b87fcaa 100644
--- a/src/test_malloc.c
+++ b/src/test_malloc.c
@@ -13,7 +13,7 @@
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
-** $Id: test_malloc.c,v 1.19 2008/03/25 09:47:35 danielk1977 Exp $
+** $Id: test_malloc.c,v 1.20 2008/03/28 07:42:54 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -546,6 +546,21 @@ static void test_memdebug_callback(int nByte, int nFrame, void **aFrame){
}
}
+static int test_memdebug_log_clear(){
+ Tcl_HashSearch search;
+ Tcl_HashEntry *pEntry;
+ for(
+ pEntry=Tcl_FirstHashEntry(&aMallocLog, &search);
+ pEntry;
+ pEntry=Tcl_NextHashEntry(&search)
+ ){
+ MallocLog *pLog = (MallocLog *)Tcl_GetHashValue(pEntry);
+ Tcl_Free((char *)pLog);
+ }
+ Tcl_DeleteHashTable(&aMallocLog);
+ Tcl_InitHashTable(&aMallocLog, MALLOC_LOG_FRAMES);
+}
+
static int test_memdebug_log(
void * clientData,
Tcl_Interp *interp,
@@ -555,8 +570,10 @@ static int test_memdebug_log(
static int isInit = 0;
int iSub;
- enum MB_enum { MB_LOG_START, MB_LOG_STOP, MB_LOG_DUMP, MB_LOG_CLEAR };
- static const char *MB_strs[] = { "start", "stop", "dump", "clear" };
+ static const char *MB_strs[] = { "start", "stop", "dump", "clear", "sync" };
+ enum MB_enum {
+ MB_LOG_START, MB_LOG_STOP, MB_LOG_DUMP, MB_LOG_CLEAR, MB_LOG_SYNC
+ };
if( !isInit ){
#ifdef SQLITE_MEMDEBUG
@@ -614,18 +631,16 @@ static int test_memdebug_log(
break;
}
case MB_LOG_CLEAR: {
- Tcl_HashSearch search;
- Tcl_HashEntry *pEntry;
- for(
- pEntry=Tcl_FirstHashEntry(&aMallocLog, &search);
- pEntry;
- pEntry=Tcl_NextHashEntry(&search)
- ){
- MallocLog *pLog = (MallocLog *)Tcl_GetHashValue(pEntry);
- Tcl_Free((char *)pLog);
- }
- Tcl_DeleteHashTable(&aMallocLog);
- Tcl_InitHashTable(&aMallocLog, MALLOC_LOG_FRAMES);
+ test_memdebug_log_clear();
+ break;
+ }
+
+ case MB_LOG_SYNC: {
+ extern void sqlite3MemdebugSync();
+ test_memdebug_log_clear();
+ mallocLogEnabled = 1;
+ sqlite3MemdebugSync();
+ break;
}
}