diff options
-rw-r--r-- | src/global.c | 15 | ||||
-rw-r--r-- | src/win32/w32_crtdbg_stacktrace.c | 7 | ||||
-rw-r--r-- | src/win32/w32_crtdbg_stacktrace.h | 2 | ||||
-rw-r--r-- | src/win32/w32_stack.c | 7 | ||||
-rw-r--r-- | src/win32/w32_stack.h | 2 |
5 files changed, 18 insertions, 15 deletions
diff --git a/src/global.c b/src/global.c index 5e9e2d96d..a2275cdde 100644 --- a/src/global.c +++ b/src/global.c @@ -29,6 +29,10 @@ git_mutex git__mwindow_mutex; typedef int (*git_global_init_fn)(void); static git_global_init_fn git__init_callbacks[] = { +#if defined(GIT_MSVC_CRTDBG) + git_win32__crtdbg_stacktrace_init, + git_win32__stack_init, +#endif git_allocator_global_init, git_threads_global_init, git_hash_global_init, @@ -70,12 +74,6 @@ static int init_common(void) size_t i; int ret; - /* Initialize the CRT debug allocator first, before our first malloc */ -#if defined(GIT_MSVC_CRTDBG) - git_win32__crtdbg_stacktrace_init(); - git_win32__stack_init(); -#endif - /* Initialize subsystems that have global state */ for (i = 0; i < ARRAY_SIZE(git__init_callbacks); i++) if ((ret = git__init_callbacks[i]()) != 0) @@ -198,11 +196,6 @@ int git_libgit2_shutdown(void) FlsFree(_fls_index); git_mutex_free(&git__mwindow_mutex); - -#if defined(GIT_MSVC_CRTDBG) - git_win32__crtdbg_stacktrace_cleanup(); - git_win32__stack_cleanup(); -#endif } /* Exit the lock */ diff --git a/src/win32/w32_crtdbg_stacktrace.c b/src/win32/w32_crtdbg_stacktrace.c index cdb5ac1a5..03078bde5 100644 --- a/src/win32/w32_crtdbg_stacktrace.c +++ b/src/win32/w32_crtdbg_stacktrace.c @@ -9,6 +9,7 @@ #if defined(GIT_MSVC_CRTDBG) #include "w32_stack.h" +#include "global.h" #define CRTDBG_STACKTRACE__UID_LEN (15) @@ -219,7 +220,7 @@ static void dump_summary(const char *label) fflush(stderr); } -void git_win32__crtdbg_stacktrace_init(void) +int git_win32__crtdbg_stacktrace_init(void) { InitializeCriticalSection(&g_crtdbg_stacktrace_cs); @@ -236,6 +237,10 @@ void git_win32__crtdbg_stacktrace_init(void) _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); LeaveCriticalSection(&g_crtdbg_stacktrace_cs); + + git__on_shutdown(git_win32__crtdbg_stacktrace_cleanup); + + return 0; } int git_win32__crtdbg_stacktrace__dump( diff --git a/src/win32/w32_crtdbg_stacktrace.h b/src/win32/w32_crtdbg_stacktrace.h index d65154bab..a3cfefb27 100644 --- a/src/win32/w32_crtdbg_stacktrace.h +++ b/src/win32/w32_crtdbg_stacktrace.h @@ -47,7 +47,7 @@ * Initialize our memory leak tracking and de-dup data structures. * This should ONLY be called by git_libgit2_init(). */ -void git_win32__crtdbg_stacktrace_init(void); +int git_win32__crtdbg_stacktrace_init(void); /** * Shutdown our memory leak tracking and dump summary data. diff --git a/src/win32/w32_stack.c b/src/win32/w32_stack.c index 78c78dbbd..d3b46f239 100644 --- a/src/win32/w32_stack.c +++ b/src/win32/w32_stack.c @@ -12,6 +12,7 @@ #include "Dbghelp.h" #include "win32/posix.h" #include "hash.h" +#include "global.h" static bool g_win32_stack_initialized = false; static HANDLE g_win32_stack_process = INVALID_HANDLE_VALUE; @@ -28,14 +29,18 @@ int git_win32__stack__set_aux_cb( return 0; } -void git_win32__stack_init(void) +int git_win32__stack_init(void) { if (!g_win32_stack_initialized) { g_win32_stack_process = GetCurrentProcess(); SymSetOptions(SYMOPT_LOAD_LINES); SymInitialize(g_win32_stack_process, NULL, TRUE); g_win32_stack_initialized = true; + + git__on_shutdown(git_win32__stack_cleanup); } + + return 0; } void git_win32__stack_cleanup(void) diff --git a/src/win32/w32_stack.h b/src/win32/w32_stack.h index c2565c228..b42ff3441 100644 --- a/src/win32/w32_stack.h +++ b/src/win32/w32_stack.h @@ -81,7 +81,7 @@ typedef struct { * thread at startup (under a lock if there are other threads * active). */ -void git_win32__stack_init(void); +int git_win32__stack_init(void); /** * Cleanup symbol table data. This should be done in the |