Skip to content

Commit 556702f

Browse files
jeffhostetlergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dce7d29 commit 556702f

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

compat/mingw.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,6 +2411,12 @@ int wmain(int argc, const wchar_t **wargv)
24112411

24122412
trace2_initialize_clock();
24132413

2414+
#ifdef _MSC_VER
2415+
#ifdef USE_MSVC_CRTDBG
2416+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
2417+
#endif
2418+
#endif
2419+
24142420
maybe_redirect_std_handles();
24152421

24162422
/* determine size of argv and environ conversion buffer */

config.mak.uname

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ else
448448
endif
449449
BASIC_CFLAGS += $(sdk_libs) $(msvc_libs)
450450

451+
ifneq ($(USE_MSVC_CRTDBG),)
452+
# Optionally enable memory leak reporting.
453+
BASIC_CFLAGS += -DUSE_MSVC_CRTDBG
454+
endif
451455
BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1
452456
# Always give "-Zi" to the compiler and "-debug" to linker (even in
453457
# release mode) to force a PDB to be generated (like RelWithDebInfo).

git-compat-util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#ifndef GIT_COMPAT_UTIL_H
22
#define GIT_COMPAT_UTIL_H
33

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+
413
#define _FILE_OFFSET_BITS 64
514

615

0 commit comments

Comments
 (0)