Check for memory leak when _DEBUG is defined
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
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 <stdlib.h>
+#include <crtdbg.h>
+#endif
#include <windows.h>
#include <stdio.h>
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 <stdlib.h>
+#include <crtdbg.h>
+#endif
#include <stdio.h>
#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 <stdlib.h>
+#include <crtdbg.h>
+#endif
#include <stdio.h>
#if defined(_WIN32)