Add ENABLE_MEMLEAK parameter to CMakeLists.txt (fix jmem.cpp so it can be compiled when MEMLEAK is defined).

This commit is contained in:
David Capello 2010-10-10 16:47:01 -03:00
parent f85070c1c6
commit f86c306bab
3 changed files with 16 additions and 11 deletions

View File

@ -16,6 +16,7 @@ option(USE_STATIC_ALLEGRO "Use static version of Allegro library" off)
option(USE_SHARED_JPEGLIB "Use your installed copy of jpeglib" off)
option(USE_SHARED_ZLIB "Use your installed copy of zlib" off)
option(USE_SHARED_LIBPNG "Use your installed copy of libpng" off)
option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)" off)
######################################################################
# Directories of third-party libraries
@ -49,6 +50,10 @@ if(USE_STATIC_ALLEGRO)
add_definitions(-DALLEGRO_STATICLINK)
endif()
if(ENABLE_MEMLEAK)
add_definitions(-DMEMLEAK)
endif()
######################################################################
# Main ASE targets

View File

@ -10,10 +10,14 @@ if(WIN32)
User32 Shell32 ComCtl32 ComDlg32 Gdi32 Msimg32
WinMM AdvAPI32 Ole32 ShLwApi Vfw32 WinInet PsApi
DDraw DxGuid DSound DInput8)
if(MSVC AND ENABLE_MEMLEAK)
set(sys_libs ${sys_libs} dbghelp)
endif()
else()
# Pthreads
set(sys_libs ${sys_libs}
pthread)
set(sys_libs ${sys_libs} pthread)
# Allegro library on Unix like systems
find_program(allegro_config "allegro-config")

View File

@ -55,13 +55,9 @@ char *jstrdup(const char *string)
//////////////////////////////////////////////////////////////////////
// With leak detection
#if defined(__GNUC__)
#define BACKTRACE_LEVELS 4
#else
#define BACKTRACE_LEVELS 16
#endif
#define BACKTRACE_LEVELS 16
#if defined _MSC_VER
#ifdef _MSC_VER
#include <windows.h>
#include <dbghelp.h>
@ -109,7 +105,7 @@ typedef struct slot_t
static bool memleak_status = false;
static slot_t* headslot;
static Mutex mutex;
static Mutex* mutex = NULL;
void _jmemleak_init()
{
@ -210,7 +206,7 @@ static void addslot(void *ptr, unsigned long size)
p->size = size;
p->next = headslot;
ScopedLock lock(mutex);
ScopedLock lock(*mutex);
headslot = p;
}
@ -223,7 +219,7 @@ static void delslot(void *ptr)
ASSERT(ptr != NULL);
ScopedLock lock(mutex);
ScopedLock lock(*mutex);
for (it=headslot; it!=NULL; prev=it, it=it->next) {
if (it->ptr == ptr) {