Commit a6fb72a8ba3bf3f8bc8d78ef4104c6b083416a4b

Edward Thomson 2021-05-18T11:51:25

tests: exit with error on win32 leakcheck

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);