From c421b7010d915a36bfc90c4f0462095ea840bb7a Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sun, 15 Mar 2015 16:09:44 -0700 Subject: Check for memory leak when _DEBUG is defined --- dlfcn.c | 5 +++++ test.c | 17 +++++++++++++++++ testdll.c | 5 +++++ 3 files changed, 27 insertions(+) diff --git a/dlfcn.c b/dlfcn.c index 75f5c81..add1f4f 100644 --- a/dlfcn.c +++ b/dlfcn.c @@ -17,6 +17,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef _DEBUG +#define _CRTDBG_MAP_ALLOC +#include +#include +#endif #include #include diff --git a/test.c b/test.c index 4dff8f0..d6280e4 100644 --- a/test.c +++ b/test.c @@ -18,6 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef _DEBUG +#define _CRTDBG_MAP_ALLOC +#include +#include +#endif #include #include "dlfcn.h" @@ -71,6 +76,15 @@ int main() int (*nonexistentfunction)( void ); int ret; +#ifdef _DEBUG + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT); + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDOUT); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDOUT); +#endif + library = dlopen( "testdll.dll", RTLD_GLOBAL ); if( !library ) { @@ -295,5 +309,8 @@ int main() else printf( "SUCCESS\tClosed global handle.\n" ); +#ifdef _DEBUG + _CrtDumpMemoryLeaks(); +#endif return 0; } diff --git a/testdll.c b/testdll.c index 2c40014..ff99f87 100644 --- a/testdll.c +++ b/testdll.c @@ -17,6 +17,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef _DEBUG +#define _CRTDBG_MAP_ALLOC +#include +#include +#endif #include #if defined(_WIN32) -- cgit v1.2.3-55-g6feb