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
diff --git a/src/test_malloc.c b/src/test_malloc.c
index 3595a06..09b87fc 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 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 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 @@
       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;
     }
   }