mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Added memory leak detection for MSVC.
This commit is contained in:
parent
a948015cf5
commit
5b543a995b
@ -46,6 +46,11 @@ else
|
||||
LIBS += Alleg.lib
|
||||
endif
|
||||
|
||||
ifdef MEMLEAK
|
||||
CFLAGS += -DMEMLEAK
|
||||
LIBS += dbghelp.lib
|
||||
endif
|
||||
|
||||
######################################################################
|
||||
# General rules
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/keyboard.h>
|
||||
#include <allegro/unicode.h>
|
||||
#include <ctype.h>
|
||||
|
@ -53,6 +53,8 @@
|
||||
`-----~---------~-------------~-----------'
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <allegro/unicode.h>
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
/* Based on code from GTK+ 2.1.2 (gtk+/gtk/gtkhbox.c) */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmessage.h"
|
||||
#include "jinete/jrect.h"
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/gfx.h>
|
||||
#include <allegro/keyboard.h>
|
||||
#include <allegro/timer.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
|
||||
static char *clipboard_text = NULL;
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
/* Based on code of AllegroFont, Copyright (c) 2001, 2002 Javier Gonzalez */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -34,6 +34,8 @@
|
||||
allegro/tools/plugins/datfont.c
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jhook.h"
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/draw.h>
|
||||
#include <allegro/gfx.h>
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jmessage.h"
|
||||
#include "jinete/jtheme.h"
|
||||
#include "jinete/jwidget.h"
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
/* #define USE_JUNKLIST */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
|
||||
#ifdef USE_JUNKLIST /* TODO warning not thread safe */
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/keyboard.h>
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
|
@ -32,6 +32,8 @@
|
||||
/* #define REPORT_EVENTS */
|
||||
/* #define LIMIT_DISPATCH_TIME */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef REPORT_EVENTS
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -76,44 +78,130 @@ char *jstrdup(const char *string)
|
||||
|
||||
#else
|
||||
|
||||
/**********************************************************************/
|
||||
/* with leak detection */
|
||||
/**********************************************************************/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// With leak detection
|
||||
|
||||
#define BACKTRACE_LEVELS 16
|
||||
|
||||
#if defined _MSC_VER
|
||||
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
// This is an implementation of the __builtin_return_address GCC
|
||||
// extension for the MSVC compiler.
|
||||
//
|
||||
// Author: Unknown
|
||||
// Modified by David Capello to return NULL when the callstack
|
||||
// is not as high as the specified "level".
|
||||
//
|
||||
__declspec (naked) void* __builtin_return_address(int level)
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push ebx
|
||||
|
||||
mov eax, ebp
|
||||
mov ebx, DWORD PTR [esp + 8] // level
|
||||
__next:
|
||||
test ebx, ebx
|
||||
je __break
|
||||
dec ebx
|
||||
mov eax, DWORD PTR [eax]
|
||||
test eax, eax
|
||||
je __done
|
||||
jmp __next
|
||||
__break:
|
||||
mov eax, DWORD PTR [eax + 4]
|
||||
__done:
|
||||
pop ebx
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct slot_t
|
||||
{
|
||||
void* backtrace[4];
|
||||
void* backtrace[BACKTRACE_LEVELS];
|
||||
void* ptr;
|
||||
unsigned long size;
|
||||
struct slot_t* next;
|
||||
} slot_t;
|
||||
|
||||
static bool memleak_status = false;
|
||||
static slot_t* headslot;
|
||||
static JMutex mutex;
|
||||
|
||||
void jmemleak_init()
|
||||
{
|
||||
assert(!memleak_status);
|
||||
|
||||
headslot = NULL;
|
||||
mutex = jmutex_new();
|
||||
|
||||
memleak_status = true;
|
||||
}
|
||||
|
||||
void jmemleak_exit()
|
||||
{
|
||||
assert(memleak_status);
|
||||
memleak_status = false;
|
||||
|
||||
FILE* f = fopen("_ase_memlog.txt", "wt");
|
||||
slot_t* it;
|
||||
|
||||
if (f != NULL) {
|
||||
/* memory leaks */
|
||||
#ifdef _MSC_VER
|
||||
struct SYMBOL_INFO_EX {
|
||||
SYMBOL_INFO header;
|
||||
char filename[512];
|
||||
} si;
|
||||
si.header.SizeOfStruct = sizeof(SYMBOL_INFO_EX);
|
||||
|
||||
IMAGEHLP_LINE line;
|
||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE);
|
||||
|
||||
HANDLE hproc = ::GetCurrentProcess();
|
||||
::SymInitialize(hproc, NULL, FALSE);
|
||||
|
||||
char filename[MAX_PATH];
|
||||
::GetModuleFileName(NULL, filename, sizeof filename);
|
||||
::SymLoadModule(hproc, NULL, filename, NULL, 0, 0);
|
||||
|
||||
char path[MAX_PATH];
|
||||
strcpy(path, filename);
|
||||
if (strrchr(path, '\\'))
|
||||
*strrchr(path, '\\') = 0;
|
||||
else
|
||||
*path = 0;
|
||||
::SymSetSearchPath(hproc, path);
|
||||
#endif
|
||||
|
||||
// Memory leaks
|
||||
for (it=headslot; it!=NULL; it=it->next) {
|
||||
fprintf(f,
|
||||
"Leak:\n%p\n%p\n%p\n%p\nptr: %p, size: %lu\n",
|
||||
it->backtrace[0],
|
||||
it->backtrace[1],
|
||||
it->backtrace[2],
|
||||
it->backtrace[3],
|
||||
it->ptr, it->size);
|
||||
fprintf(f, "\nLEAK address: %p, size: %lu\n", it->ptr, it->size);
|
||||
|
||||
for (int c=0; c<BACKTRACE_LEVELS; ++c) {
|
||||
#ifdef _MSC_VER
|
||||
DWORD displacement;
|
||||
if (::SymGetLineFromAddr(hproc, (DWORD)it->backtrace[c], &displacement, &line) &&
|
||||
::SymFromAddr(hproc, (DWORD)it->backtrace[c], NULL, &si.header)) {
|
||||
fprintf(f, "%p : %s(%lu) [%s]\n",
|
||||
it->backtrace[c],
|
||||
line.FileName, line.LineNumber,
|
||||
si.header.Name);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
fprintf(f, "%p\n", it->backtrace[c]);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
::SymCleanup(hproc);
|
||||
#endif
|
||||
}
|
||||
|
||||
jmutex_free(mutex);
|
||||
@ -121,15 +209,18 @@ void jmemleak_exit()
|
||||
|
||||
static void addslot(void *ptr, unsigned long size)
|
||||
{
|
||||
if (!memleak_status)
|
||||
return;
|
||||
|
||||
slot_t* p = reinterpret_cast<slot_t*>(malloc(sizeof(slot_t)));
|
||||
|
||||
assert(ptr != NULL);
|
||||
assert(size != 0);
|
||||
|
||||
p->backtrace[0] = __builtin_return_address(4); /* a GCC extension */
|
||||
p->backtrace[1] = __builtin_return_address(3);
|
||||
p->backtrace[2] = __builtin_return_address(2);
|
||||
p->backtrace[3] = __builtin_return_address(1);
|
||||
// __builtin_return_address is a GCC extension
|
||||
for (int c=0; c<BACKTRACE_LEVELS; ++c)
|
||||
p->backtrace[c] = __builtin_return_address(BACKTRACE_LEVELS-c);
|
||||
|
||||
p->ptr = ptr;
|
||||
p->size = size;
|
||||
p->next = headslot;
|
||||
@ -141,6 +232,9 @@ static void addslot(void *ptr, unsigned long size)
|
||||
|
||||
static void delslot(void *ptr)
|
||||
{
|
||||
if (!memleak_status)
|
||||
return;
|
||||
|
||||
slot_t *it, *prev = NULL;
|
||||
|
||||
assert(ptr != NULL);
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/keyboard.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmessage.h"
|
||||
#include "jinete/jrect.h"
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jaccel.h"
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmenu.h"
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jrect.h"
|
||||
|
||||
JRect jrect_new(int x1, int y1, int x2, int y2)
|
||||
|
@ -1,3 +1,36 @@
|
||||
/* Jinete - a GUI library
|
||||
* Copyright (C) 2003-2009 David Capello.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of the author nor the names of its contributors may
|
||||
* be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <allegro.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmessage.h"
|
||||
#include "jinete/jrect.h"
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
#include "jinete/jfont.h"
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
/* jstream_string is based on streams of HTMLEX */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <cctype>
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <allegro.h>
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro/keyboard.h>
|
||||
#include <math.h>
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <allegro/internal/aintern.h>
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <allegro.h>
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "jinete/jintern.h"
|
||||
#include "jinete/jlist.h"
|
||||
#include "jinete/jmessage.h"
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
/* #define REPORT_SIGNALS */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
@ -32,6 +32,8 @@
|
||||
#define REDRAW_MOVEMENT
|
||||
#define MOTION_CURSOR JI_CURSOR_NORMAL
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <allegro.h>
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
@ -29,6 +29,8 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -908,7 +908,7 @@ static bool editor_msg_proc(JWidget widget, JMessage msg)
|
||||
case JM_DESTROY:
|
||||
jmanager_remove_timer(editor->mask_timer_id);
|
||||
remove_editor(widget);
|
||||
jfree(editor_data(widget));
|
||||
jfree(editor);
|
||||
break;
|
||||
|
||||
case JM_REQSIZE:
|
||||
|
Loading…
x
Reference in New Issue
Block a user