2008-09-18 03:15:49 +00:00
|
|
|
#ifdef _DEBUG
|
2015-09-23 13:23:11 +00:00
|
|
|
|
|
|
|
#if (defined(_MSC_VER) && (_MSC_VER < 1900))
|
2008-09-18 03:15:49 +00:00
|
|
|
#define MEM_LEAK_TEST
|
2015-09-23 13:23:11 +00:00
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
#ifdef MEM_LEAK_TEST
|
|
|
|
|
|
|
|
#ifndef __MEM_TEST__H__
|
|
|
|
#define __MEM_TEST__H__
|
|
|
|
#pragma warning(disable:4786)
|
|
|
|
#pragma warning(disable:4291)
|
|
|
|
|
2010-09-22 21:43:42 +00:00
|
|
|
#ifndef _WIN32_WINNT
|
|
|
|
#define _WIN32_WINNT 0x0500
|
|
|
|
#endif
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2012-09-22 05:53:39 +00:00
|
|
|
#include <xdebug>
|
|
|
|
#include <xlocale>
|
|
|
|
#include <xiosbase>
|
|
|
|
#include <xtree>
|
|
|
|
|
|
|
|
#define new new(__FILE__, __LINE__)
|
2010-09-22 21:43:42 +00:00
|
|
|
#include <map>
|
2012-09-22 05:53:39 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#undef new
|
|
|
|
|
|
|
|
/*
|
2010-09-22 21:43:42 +00:00
|
|
|
#include <crtdbg.h>
|
2008-09-18 03:15:49 +00:00
|
|
|
#include <malloc.h>
|
2010-09-22 21:43:42 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <xlocnum>
|
|
|
|
#include <xlocmon>
|
|
|
|
#include <sstream>
|
|
|
|
#include <list>
|
2012-09-22 05:53:39 +00:00
|
|
|
*/
|
2008-09-18 03:15:49 +00:00
|
|
|
|
2010-09-22 21:43:42 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char File[300];
|
|
|
|
int line;
|
|
|
|
int size;
|
|
|
|
int order;
|
|
|
|
} DEBUG_LOCATION;
|
|
|
|
|
|
|
|
typedef std::map<void *, DEBUG_LOCATION> MEMLIST;
|
|
|
|
typedef MEMLIST::iterator MEMLIST_ITER;
|
|
|
|
|
|
|
|
class CMemList {
|
|
|
|
MEMLIST MemList;
|
|
|
|
HANDLE hSemaphone;
|
|
|
|
DWORD ThreadID;
|
|
|
|
HMODULE m_hModule;
|
|
|
|
|
|
|
|
enum INIT { Initialized = 123, NotInitialized };
|
|
|
|
INIT State;
|
|
|
|
int order;
|
|
|
|
bool LogAllocate;
|
|
|
|
|
|
|
|
void Insert(void *res, DEBUG_LOCATION &info);
|
|
|
|
void Remove(void *ptr);
|
|
|
|
|
|
|
|
public:
|
|
|
|
CMemList();
|
|
|
|
~CMemList();
|
|
|
|
void * AddItem ( size_t size, char * filename, int line );
|
|
|
|
void * ReAllocItem ( void * ptr, size_t size, const char * filename, int line );
|
2010-10-23 18:53:01 +00:00
|
|
|
void removeItem ( void * ptr, bool bFree );
|
2010-09-22 21:43:42 +00:00
|
|
|
void RecordAddItem ( void * ptr, size_t size, const char * filename, int line );
|
|
|
|
};
|
|
|
|
|
2008-09-18 03:15:49 +00:00
|
|
|
void* operator new (size_t size );
|
|
|
|
void* operator new (size_t size, char* filename, int line);
|
|
|
|
void* operator new [] (size_t size );
|
|
|
|
void* operator new [] (size_t size, char* filename, int line);
|
|
|
|
void operator delete ( void* ptr);
|
|
|
|
void operator delete[](void* ptr);
|
|
|
|
|
2010-09-22 21:43:42 +00:00
|
|
|
void* MemTest_malloc(size_t size, char* filename, int line);
|
|
|
|
void* MemTest_realloc(void* ptr, size_t size, char* filename, int line);
|
|
|
|
void MemTest_AddLeak(char* Comment);
|
|
|
|
LPVOID MemTest_VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect, LPCSTR filename, int line);
|
|
|
|
BOOL MemTest_VirtualFree( LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType );
|
2008-09-18 03:15:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-09-22 21:43:42 +00:00
|
|
|
#undef new
|
2008-09-18 03:15:49 +00:00
|
|
|
#undef malloc
|
|
|
|
#undef free
|
2010-09-22 21:43:42 +00:00
|
|
|
#define new new(__FILE__, __LINE__)
|
2008-09-18 03:15:49 +00:00
|
|
|
#define malloc(x) (MemTest_malloc((x),__FILE__, __LINE__))
|
|
|
|
#define realloc(mem,x) (MemTest_realloc((mem),(x),__FILE__, __LINE__))
|
2010-09-22 21:43:42 +00:00
|
|
|
#define free(x) (delete (x))
|
2008-09-18 03:15:49 +00:00
|
|
|
#define VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect ) \
|
|
|
|
(MemTest_VirtualAlloc((lpAddress), (dwSize), (flAllocationType), (flProtect),__FILE__, __LINE__))
|
|
|
|
#define VirtualFree(lpAddress, dwSize, dwFreeType ) \
|
|
|
|
(MemTest_VirtualFree((lpAddress), (dwSize), (dwFreeType)))
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-01-31 19:27:27 +00:00
|
|
|
#endif
|