msvc: add a compile-time flag to allow detailed heap debugging

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>

Jeff Hostetler committed Jun 25, 2019 at 07:49 UTC 556702f86cb043f18bf46dceec25fe1e783c4590
3 files changed +19
compat/mingw.c
+6
@@ -2411,6 +2411,12 @@ int wmain(int argc, const wchar_t **wargv)
2411
2412 trace2_initialize_clock();
2413
2414 +#ifdef _MSC_VER
2415 +#ifdef USE_MSVC_CRTDBG
2416 + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2417 +#endif
2418 +#endif
2419 +
2420 maybe_redirect_std_handles();
2421
2422 /* determine size of argv and environ conversion buffer */
config.mak.uname
+4
@@ -448,6 +448,10 @@ else
448 endif
449 BASIC_CFLAGS += $(sdk_libs) $(msvc_libs)
450
451 +ifneq ($(USE_MSVC_CRTDBG),)
452 + # Optionally enable memory leak reporting.
453 + BASIC_CFLAGS += -DUSE_MSVC_CRTDBG
454 +endif
455 BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
456 # Always give "-Zi" to the compiler and "-debug" to linker (even in
457 # release mode) to force a PDB to be generated (like RelWithDebInfo).
git-compat-util.h
+9
@@ -1,6 +1,15 @@
1 #ifndef GIT_COMPAT_UTIL_H
2 #define GIT_COMPAT_UTIL_H
3
4 +#ifdef USE_MSVC_CRTDBG
5 +/*
6 + * For these to work they must appear very early in each
7 + * file -- before most of the standard header files.
8 + */
9 +#include <stdlib.h>
10 +#include <crtdbg.h>
11 +#endif
12 +
13 #define _FILE_OFFSET_BITS 64
14
15