tests: exit with error on win32 leakcheck
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/src/win32/w32_leakcheck.c b/src/win32/w32_leakcheck.c
index ef17004..5c8425b 100644
--- a/src/win32/w32_leakcheck.c
+++ b/src/win32/w32_leakcheck.c
@@ -558,6 +558,11 @@ static void git_win32_leakcheck_global_shutdown(void)
git_win32_leakcheck_stack_cleanup();
}
+bool git_win32_leakcheck_has_leaks(void)
+{
+ return (g_transient_count_total_leaks > 0);
+}
+
int git_win32_leakcheck_global_init(void)
{
git_win32_leakcheck_stacktrace_init();
diff --git a/src/win32/w32_leakcheck.h b/src/win32/w32_leakcheck.h
index 7da03ab..cb45e36 100644
--- a/src/win32/w32_leakcheck.h
+++ b/src/win32/w32_leakcheck.h
@@ -21,6 +21,8 @@ int git_win32_leakcheck_global_init(void);
#include "git2/errors.h"
#include "strnlen.h"
+bool git_win32_leakcheck_has_leaks(void);
+
/* Stack frames (for stack tracing, below) */
/**
diff --git a/tests/main.c b/tests/main.c
index 00b2bae..207a6a8 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -1,6 +1,10 @@
#include "clar_libgit2.h"
#include "clar_libgit2_trace.h"
+#ifdef GIT_WIN32_LEAKCHECK
+# include "win32/w32_leakcheck.h"
+#endif
+
#ifdef _WIN32
int __cdecl main(int argc, char *argv[])
#else
@@ -29,6 +33,11 @@ int main(int argc, char *argv[])
cl_global_trace_disable();
git_libgit2_shutdown();
+#ifdef GIT_WIN32_LEAKCHECK
+ if (git_win32_leakcheck_has_leaks())
+ res = res || 1;
+#endif
+
at_exit_cmd = getenv("CLAR_AT_EXIT");
if (at_exit_cmd != NULL) {
int at_exit = system(at_exit_cmd);