Commit 4a0dceeb by lhchavez

Make the Windows leak detection more robust

This change:

* Increases MY_ROW_LIMIT to 2M, since it has been failing in #5595's
  tests since it's _super_ close to the limit.
* Calls `git_repository_free()` on a `git_repository` that was being
  leaked only in Windows.
* Marks the global `git_repository` on `tests/repo/init.c` as `NULL`
  after being freed to make any accidental access more noisy.
* Uses `cl_assert_equal_i()` in `test_trace_windows_stacktrace__leaks`
  to make the test failures more actionable.
* Renames the globals in `tests/repo/init.c` so that they don't start
  with an underscore.
parent 2e5f27c7
...@@ -57,7 +57,7 @@ static CRITICAL_SECTION g_crtdbg_stacktrace_cs; ...@@ -57,7 +57,7 @@ static CRITICAL_SECTION g_crtdbg_stacktrace_cs;
* it and try again. * it and try again.
*/ */
#define MY_ROW_LIMIT (1024 * 1024) #define MY_ROW_LIMIT (2 * 1024 * 1024)
static git_win32__crtdbg_stacktrace__row g_cs_rows[MY_ROW_LIMIT]; static git_win32__crtdbg_stacktrace__row g_cs_rows[MY_ROW_LIMIT];
static git_win32__crtdbg_stacktrace__row *g_cs_index[MY_ROW_LIMIT]; static git_win32__crtdbg_stacktrace__row *g_cs_index[MY_ROW_LIMIT];
......
...@@ -58,47 +58,48 @@ void test_trace_windows_stacktrace__leaks(void) ...@@ -58,47 +58,48 @@ void test_trace_windows_stacktrace__leaks(void)
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"p1"); "p1");
cl_assert((leaks == 1)); cl_assert_equal_i(1, leaks);
p2 = git__malloc(5); p2 = git__malloc(5);
leaks = git_win32__crtdbg_stacktrace__dump( leaks = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"p1,p2"); "p1,p2");
cl_assert((leaks == 2)); cl_assert_equal_i(2, leaks);
p3 = git__malloc(5); p3 = git__malloc(5);
leaks = git_win32__crtdbg_stacktrace__dump( leaks = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"p1,p2,p3"); "p1,p2,p3");
cl_assert((leaks == 3)); cl_assert_equal_i(3, leaks);
git__free(p2); git__free(p2);
leaks = git_win32__crtdbg_stacktrace__dump( leaks = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"p1,p3"); "p1,p3");
cl_assert((leaks == 2)); cl_assert_equal_i(2, leaks);
/* move the mark. only new leaks should appear afterwards */ /* move the mark. only new leaks should appear afterwards */
error = git_win32__crtdbg_stacktrace__dump( error = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__SET_MARK, GIT_WIN32__CRTDBG_STACKTRACE__SET_MARK,
NULL); NULL);
cl_assert((error == 0)); /* cannot use cl_git_pass() since that may allocate memory. */
cl_assert_equal_i(0, error);
leaks = git_win32__crtdbg_stacktrace__dump( leaks = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"not_p1,not_p3"); "not_p1,not_p3");
cl_assert((leaks == 0)); cl_assert_equal_i(0, leaks);
p4 = git__malloc(5); p4 = git__malloc(5);
leaks = git_win32__crtdbg_stacktrace__dump( leaks = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"p4,not_p1,not_p3"); "p4,not_p1,not_p3");
cl_assert((leaks == 1)); cl_assert_equal_i(1, leaks);
git__free(p1); git__free(p1);
git__free(p3); git__free(p3);
...@@ -106,21 +107,21 @@ void test_trace_windows_stacktrace__leaks(void) ...@@ -106,21 +107,21 @@ void test_trace_windows_stacktrace__leaks(void)
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"p4"); "p4");
cl_assert((leaks == 1)); cl_assert_equal_i(1, leaks);
git__free(p4); git__free(p4);
leaks = git_win32__crtdbg_stacktrace__dump( leaks = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
"end"); "end");
cl_assert((leaks == 0)); cl_assert_equal_i(0, leaks);
/* confirm current absolute leaks count matches beginning value. */ /* confirm current absolute leaks count matches beginning value. */
after = git_win32__crtdbg_stacktrace__dump( after = git_win32__crtdbg_stacktrace__dump(
GIT_WIN32__CRTDBG_STACKTRACE__QUIET | GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL, GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL,
"total"); "total");
cl_assert((before == after)); cl_assert_equal_i(before, after);
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment