/ Check-in [f1b97ed9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f1b97ed93183378ff56b4fe7ae8ea269c24092fc
User & Date: danielk1977 2008-03-28 07:42:54
Context
2008-03-28
12:53
Patch to the new memory tracing logic that allows it to build even if memory debugging is turned off. (CVS 4927) check-in: 0a9c63b2 user: drh tags: trunk
07:42
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) check-in: f1b97ed9 user: danielk1977 tags: trunk
2008-03-27
22:42
Allow the xAccess method in the VFS to return -1 to signal an I/O error, and in particular an SQLITE_IOERR_NOMEM. (CVS 4925) check-in: 3cb704c4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mem2.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains the C functions that implement a memory
    13     13   ** allocation subsystem for use by SQLite.  
    14     14   **
    15         -** $Id: mem2.c,v 1.23 2008/03/21 14:22:44 danielk1977 Exp $
           15  +** $Id: mem2.c,v 1.24 2008/03/28 07:42:54 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** This version of the memory allocator is used only if the
    21     21   ** SQLITE_MEMDEBUG macro is defined
    22     22   */
................................................................................
   405    405     enterMem();
   406    406     if( n>=sizeof(mem.zTitle) ) n = sizeof(mem.zTitle)-1;
   407    407     memcpy(mem.zTitle, zTitle, n);
   408    408     mem.zTitle[n] = 0;
   409    409     mem.nTitle = (n+3)&~3;
   410    410     sqlite3_mutex_leave(mem.mutex);
   411    411   }
          412  +
          413  +void sqlite3MemdebugSync(){
          414  +  struct MemBlockHdr *pHdr;
          415  +  for(pHdr=mem.pFirst; pHdr; pHdr=pHdr->pNext){
          416  +    void **pBt = (void**)pHdr;
          417  +    pBt -= pHdr->nBacktraceSlots;
          418  +    mem.xBacktrace(pHdr->iSize, pHdr->nBacktrace-1, &pBt[1]);
          419  +  }
          420  +}
   412    421   
   413    422   /*
   414    423   ** Open the file indicated and write a log of all unfreed memory 
   415    424   ** allocations into that log.
   416    425   */
   417    426   void sqlite3MemdebugDump(const char *zFilename){
   418    427     FILE *out;

Changes to src/test_malloc.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** This file contains code used to implement test interfaces to the
    14     14   ** memory allocation subsystem.
    15     15   **
    16         -** $Id: test_malloc.c,v 1.19 2008/03/25 09:47:35 danielk1977 Exp $
           16  +** $Id: test_malloc.c,v 1.20 2008/03/28 07:42:54 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
    22     22   #include <assert.h>
    23     23   
................................................................................
   541    541         pLog = (MallocLog *)Tcl_GetHashValue(pEntry);
   542    542       }
   543    543   
   544    544       pLog->nCall++;
   545    545       pLog->nByte += nByte;
   546    546     }
   547    547   }
          548  +
          549  +static int test_memdebug_log_clear(){
          550  +  Tcl_HashSearch search;
          551  +  Tcl_HashEntry *pEntry;
          552  +  for(
          553  +    pEntry=Tcl_FirstHashEntry(&aMallocLog, &search);
          554  +    pEntry;
          555  +    pEntry=Tcl_NextHashEntry(&search)
          556  +  ){
          557  +    MallocLog *pLog = (MallocLog *)Tcl_GetHashValue(pEntry);
          558  +    Tcl_Free((char *)pLog);
          559  +  }
          560  +  Tcl_DeleteHashTable(&aMallocLog);
          561  +  Tcl_InitHashTable(&aMallocLog, MALLOC_LOG_FRAMES);
          562  +}
   548    563   
   549    564   static int test_memdebug_log(
   550    565     void * clientData,
   551    566     Tcl_Interp *interp,
   552    567     int objc,
   553    568     Tcl_Obj *CONST objv[]
   554    569   ){
   555    570     static int isInit = 0;
   556    571     int iSub;
   557    572   
   558         -  enum MB_enum { MB_LOG_START, MB_LOG_STOP, MB_LOG_DUMP, MB_LOG_CLEAR };
   559         -  static const char *MB_strs[] = { "start", "stop", "dump", "clear" };
          573  +  static const char *MB_strs[] = { "start", "stop", "dump", "clear", "sync" };
          574  +  enum MB_enum { 
          575  +      MB_LOG_START, MB_LOG_STOP, MB_LOG_DUMP, MB_LOG_CLEAR, MB_LOG_SYNC 
          576  +  };
   560    577   
   561    578     if( !isInit ){
   562    579   #ifdef SQLITE_MEMDEBUG
   563    580       extern void sqlite3MemdebugBacktraceCallback(
   564    581           void (*xBacktrace)(int, int, void **));
   565    582       sqlite3MemdebugBacktraceCallback(test_memdebug_callback);
   566    583   #endif
................................................................................
   610    627           );
   611    628         }
   612    629   
   613    630         Tcl_SetObjResult(interp, pRet);
   614    631         break;
   615    632       }
   616    633       case MB_LOG_CLEAR: {
   617         -      Tcl_HashSearch search;
   618         -      Tcl_HashEntry *pEntry;
   619         -      for(
   620         -        pEntry=Tcl_FirstHashEntry(&aMallocLog, &search);
   621         -        pEntry;
   622         -        pEntry=Tcl_NextHashEntry(&search)
   623         -      ){
   624         -        MallocLog *pLog = (MallocLog *)Tcl_GetHashValue(pEntry);
   625         -        Tcl_Free((char *)pLog);
   626         -      }
   627         -      Tcl_DeleteHashTable(&aMallocLog);
   628         -      Tcl_InitHashTable(&aMallocLog, MALLOC_LOG_FRAMES);
          634  +      test_memdebug_log_clear();
          635  +      break;
          636  +    }
          637  +
          638  +    case MB_LOG_SYNC: {
          639  +      extern void sqlite3MemdebugSync();
          640  +      test_memdebug_log_clear();
          641  +      mallocLogEnabled = 1;
          642  +      sqlite3MemdebugSync();
          643  +      break;
   629    644       }
   630    645     }
   631    646   
   632    647     return TCL_OK;
   633    648   }
   634    649   
   635    650   /*

Changes to test/tester.tcl.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements some common TCL routines used for regression
    12     12   # testing the SQLite library
    13     13   #
    14         -# $Id: tester.tcl,v 1.110 2008/03/22 01:08:01 drh Exp $
           14  +# $Id: tester.tcl,v 1.111 2008/03/28 07:42:54 danielk1977 Exp $
    15     15   
    16     16   
    17     17   set tcl_precision 15
    18     18   set sqlite_pending_byte 0x0010000
    19     19   
    20     20   # 
    21     21   # Check the command-line arguments for a default soft-heap-limit.
................................................................................
   256    256       puts "Number of malloc()  : [sqlite3_memdebug_malloc_count] calls"
   257    257     }
   258    258     if {[info exists ::tester_do_malloctrace]} {
   259    259       puts "Writing mallocs.sql..."
   260    260       memdebug_log_sql
   261    261       sqlite3_memdebug_log stop
   262    262       sqlite3_memdebug_log clear
          263  +
          264  +    if {[sqlite3_memory_used]>0} {
          265  +      puts "Writing leaks.sql..."
          266  +      sqlite3_memdebug_log sync
          267  +      memdebug_log_sql leaks.sql
          268  +    }
   263    269     }
   264    270     foreach f [glob -nocomplain test.db-*-journal] {
   265    271       file delete -force $f
   266    272     }
   267    273     foreach f [glob -nocomplain test.db-mj*] {
   268    274       file delete -force $f
   269    275     }