Merge pull request #5892 from libgit2/ethomson/memleak tests: clean up memory leak, fail on leak for win32
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
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);
diff --git a/tests/refs/races.c b/tests/refs/races.c
index 9134bf9..4767893 100644
--- a/tests/refs/races.c
+++ b/tests/refs/races.c
@@ -31,10 +31,12 @@ void test_refs_races__create_matching_zero_old(void)
git_oid_fromstr(&zero_id, "0000000000000000000000000000000000000000");
cl_git_fail(git_reference_create_matching(&ref, g_repo, refname, &id, 1, &zero_id, NULL));
+ git_reference_free(ref);
cl_git_pass(git_reference_create_matching(&ref, g_repo, other_refname, &id, 1, &zero_id, NULL));
- cl_git_fail(git_reference_create_matching(&ref, g_repo, other_refname, &id, 1, &zero_id, NULL));
+ git_reference_free(ref);
+ cl_git_fail(git_reference_create_matching(&ref, g_repo, other_refname, &id, 1, &zero_id, NULL));
git_reference_free(ref);
}