summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compat/mingw.c6
-rw-r--r--config.mak.uname4
-rw-r--r--git-compat-util.h9
3 files changed, 19 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index c063ae6..6672858 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2411,6 +2411,12 @@ int wmain(int argc, const wchar_t **wargv)
trace2_initialize_clock();
+#ifdef _MSC_VER
+#ifdef USE_MSVC_CRTDBG
+ _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+#endif
+#endif
+
maybe_redirect_std_handles();
/* determine size of argv and environ conversion buffer */
diff --git a/config.mak.uname b/config.mak.uname
index b8c52e4..3fde48c 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -448,6 +448,10 @@ else
endif
BASIC_CFLAGS += $(sdk_libs) $(msvc_libs)
+ifneq ($(USE_MSVC_CRTDBG),)
+ # Optionally enable memory leak reporting.
+ BASIC_CFLAGS += -DUSE_MSVC_CRTDBG
+endif
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
# Always give "-Zi" to the compiler and "-debug" to linker (even in
# release mode) to force a PDB to be generated (like RelWithDebInfo).
diff --git a/git-compat-util.h b/git-compat-util.h
index cc0e7e9..83be89d 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1,6 +1,15 @@
#ifndef GIT_COMPAT_UTIL_H
#define GIT_COMPAT_UTIL_H
+#ifdef USE_MSVC_CRTDBG
+/*
+ * For these to work they must appear very early in each
+ * file -- before most of the standard header files.
+ */
+#include <stdlib.h>
+#include <crtdbg.h>
+#endif
+
#define _FILE_OFFSET_BITS 64