]> git.ipfire.org Git - thirdparty/git.git/commitdiff
msvc: add a compile-time flag to allow detailed heap debugging
authorJeff Hostetler <jeffhost@microsoft.com>
Tue, 25 Jun 2019 14:49:40 +0000 (07:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Jun 2019 17:46:57 +0000 (10:46 -0700)
MS Visual C comes with a few neat features we can use to analyze the
heap consumption (i.e. leaks, max memory, etc).

With this patch, we introduce support via the build-time flag
`USE_MSVC_CRTDBG`.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
compat/mingw.c
config.mak.uname
git-compat-util.h

index c063ae62be125f33418684039bd3fbc21433b83b..667285887a0c536f4b33fcb8cfa7451f23936b69 100644 (file)
@@ -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 */
index b8c52e49d23ac304f07b136f5284a590f02102cb..3fde48c64da61c6964ea5584aa5c27ec5dcbc389 100644 (file)
@@ -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).
index cc0e7e97334ec90a355f9c8eb088c6810a91193c..83be89de0aac7c96799635e3b2858a465f440acf 100644 (file)
@@ -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