Commit 4a0dceebe4038b2b14460956105100d159c2e628

lhchavez 2020-10-11T17:53:10

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.

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
diff --git a/src/win32/w32_crtdbg_stacktrace.c b/src/win32/w32_crtdbg_stacktrace.c
index cdb5ac1..22a353d 100644
--- a/src/win32/w32_crtdbg_stacktrace.c
+++ b/src/win32/w32_crtdbg_stacktrace.c
@@ -57,7 +57,7 @@ static CRITICAL_SECTION g_crtdbg_stacktrace_cs;
  * 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_index[MY_ROW_LIMIT];
 
diff --git a/tests/repo/init.c b/tests/repo/init.c
index ba00d29..b86e09a 100644
--- a/tests/repo/init.c
+++ b/tests/repo/init.c
@@ -11,30 +11,30 @@ enum repo_mode {
 	BARE_REPOSITORY = 1
 };
 
-static git_repository *_repo = NULL;
-static git_buf _global_path = GIT_BUF_INIT;
+static git_repository *g_repo = NULL;
+static git_buf g_global_path = GIT_BUF_INIT;
 
 void test_repo_init__initialize(void)
 {
-	_repo = NULL;
+	g_repo = NULL;
 
 	git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
-			 &_global_path);
+			 &g_global_path);
 }
 
 void test_repo_init__cleanup(void)
 {
 	git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
-		_global_path.ptr);
-	git_buf_dispose(&_global_path);
+		g_global_path.ptr);
+	git_buf_dispose(&g_global_path);
 
 	cl_fixture_cleanup("tmp_global_path");
 }
 
 static void cleanup_repository(void *path)
 {
-	git_repository_free(_repo);
-	_repo = NULL;
+	git_repository_free(g_repo);
+	g_repo = NULL;
 
 	cl_fixture_cleanup((const char *)path);
 }
@@ -49,9 +49,9 @@ static void ensure_repository_init(
 
 	cl_assert(!git_path_isdir(working_directory));
 
-	cl_git_pass(git_repository_init(&_repo, working_directory, is_bare));
+	cl_git_pass(git_repository_init(&g_repo, working_directory, is_bare));
 
-	workdir = git_repository_workdir(_repo);
+	workdir = git_repository_workdir(g_repo);
 	if (workdir != NULL || expected_working_directory != NULL) {
 		cl_assert(
 			git__suffixcmp(workdir, expected_working_directory) == 0
@@ -59,19 +59,19 @@ static void ensure_repository_init(
 	}
 
 	cl_assert(
-		git__suffixcmp(git_repository_path(_repo), expected_path_repository) == 0
+		git__suffixcmp(git_repository_path(g_repo), expected_path_repository) == 0
 	);
 
-	cl_assert(git_repository_is_bare(_repo) == is_bare);
+	cl_assert(git_repository_is_bare(g_repo) == is_bare);
 
 #ifdef GIT_WIN32
 	if (!is_bare) {
-		DWORD fattrs = GetFileAttributes(git_repository_path(_repo));
+		DWORD fattrs = GetFileAttributes(git_repository_path(g_repo));
 		cl_assert((fattrs & FILE_ATTRIBUTE_HIDDEN) != 0);
 	}
 #endif
 
-	cl_assert(git_repository_is_empty(_repo));
+	cl_assert(git_repository_is_empty(g_repo));
 }
 
 void test_repo_init__standard_repo(void)
@@ -112,13 +112,14 @@ void test_repo_init__bare_repo_escaping_current_workdir(void)
 	cl_git_pass(chdir(git_buf_cstr(&path_repository)));
 
 	/* Initialize a bare repo with a relative path escaping out of the current working directory */
-	cl_git_pass(git_repository_init(&_repo, "../d/e.git", 1));
-	cl_git_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/"));
+	cl_git_pass(git_repository_init(&g_repo, "../d/e.git", 1));
+	cl_git_pass(git__suffixcmp(git_repository_path(g_repo), "/a/b/d/e.git/"));
 
-	git_repository_free(_repo);
+	git_repository_free(g_repo);
+	g_repo = NULL;
 
 	/* Open a bare repo with a relative path escaping out of the current working directory */
-	cl_git_pass(git_repository_open(&_repo, "../d/e.git"));
+	cl_git_pass(git_repository_open(&g_repo, "../d/e.git"));
 
 	cl_git_pass(chdir(git_buf_cstr(&path_current_workdir)));
 
@@ -133,11 +134,12 @@ void test_repo_init__reinit_bare_repo(void)
 	cl_set_cleanup(&cleanup_repository, "reinit.git");
 
 	/* Initialize the repository */
-	cl_git_pass(git_repository_init(&_repo, "reinit.git", 1));
-	git_repository_free(_repo);
+	cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
+	git_repository_free(g_repo);
+	g_repo = NULL;
 
 	/* Reinitialize the repository */
-	cl_git_pass(git_repository_init(&_repo, "reinit.git", 1));
+	cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
 }
 
 void test_repo_init__reinit_too_recent_bare_repo(void)
@@ -145,8 +147,8 @@ void test_repo_init__reinit_too_recent_bare_repo(void)
 	git_config *config;
 
 	/* Initialize the repository */
-	cl_git_pass(git_repository_init(&_repo, "reinit.git", 1));
-	git_repository_config(&config, _repo);
+	cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
+	git_repository_config(&config, g_repo);
 
 	/*
 	 * Hack the config of the repository to make it look like it has
@@ -155,10 +157,11 @@ void test_repo_init__reinit_too_recent_bare_repo(void)
 	cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 42));
 
 	git_config_free(config);
-	git_repository_free(_repo);
+	git_repository_free(g_repo);
+	g_repo = NULL;
 
 	/* Try to reinitialize the repository */
-	cl_git_fail(git_repository_init(&_repo, "reinit.git", 1));
+	cl_git_fail(git_repository_init(&g_repo, "reinit.git", 1));
 
 	cl_fixture_cleanup("reinit.git");
 }
@@ -172,15 +175,15 @@ void test_repo_init__additional_templates(void)
 	ensure_repository_init("tester", 0, "tester/.git/", "tester/");
 
 	cl_git_pass(
-		git_buf_joinpath(&path, git_repository_path(_repo), "description"));
+		git_buf_joinpath(&path, git_repository_path(g_repo), "description"));
 	cl_assert(git_path_isfile(git_buf_cstr(&path)));
 
 	cl_git_pass(
-		git_buf_joinpath(&path, git_repository_path(_repo), "info/exclude"));
+		git_buf_joinpath(&path, git_repository_path(g_repo), "info/exclude"));
 	cl_assert(git_path_isfile(git_buf_cstr(&path)));
 
 	cl_git_pass(
-		git_buf_joinpath(&path, git_repository_path(_repo), "hooks"));
+		git_buf_joinpath(&path, git_repository_path(g_repo), "hooks"));
 	cl_assert(git_path_isdir(git_buf_cstr(&path)));
 	/* won't confirm specific contents of hooks dir since it may vary */
 
@@ -197,9 +200,9 @@ static void assert_config_entry_on_init_bytype(
 
 	cl_set_cleanup(&cleanup_repository, "config_entry");
 
-	cl_git_pass(git_repository_init(&_repo, repo_path, is_bare));
+	cl_git_pass(git_repository_init(&g_repo, repo_path, is_bare));
 
-	cl_git_pass(git_repository_config(&config, _repo));
+	cl_git_pass(git_repository_config(&config, g_repo));
 	error = git_config_get_bool(&current_value, config, config_key);
 	git_config_free(config);
 
@@ -215,7 +218,8 @@ static void assert_config_entry_on_init(
 	const char *config_key, int expected_value)
 {
 	assert_config_entry_on_init_bytype(config_key, expected_value, true);
-	git_repository_free(_repo);
+	git_repository_free(g_repo);
+	g_repo = NULL;
 
 	assert_config_entry_on_init_bytype(config_key, expected_value, false);
 }
@@ -262,10 +266,10 @@ void test_repo_init__symlinks_win32_enabled_by_global_config(void)
 	 * Create a new repository (can't use `assert_config_on_init` since we
 	 * want to examine configuration levels with more granularity.)
 	 */
-	cl_git_pass(git_repository_init(&_repo, "config_entry/test.non.bare.git", false));
+	cl_git_pass(git_repository_init(&g_repo, "config_entry/test.non.bare.git", false));
 
 	/* Ensure that core.symlinks remains set (via the global config). */
-	cl_git_pass(git_repository_config(&config, _repo));
+	cl_git_pass(git_repository_config(&config, g_repo));
 	cl_git_pass(git_config_get_bool(&val, config, "core.symlinks"));
 	cl_assert_equal_i(1, val);
 
@@ -278,6 +282,9 @@ void test_repo_init__symlinks_win32_enabled_by_global_config(void)
 	git_config_free(repo_config);
 
 	git_config_free(config);
+
+	git_repository_free(g_repo);
+	g_repo = NULL;
 #endif
 }
 
@@ -324,18 +331,18 @@ void test_repo_init__reinit_doesnot_overwrite_ignorecase(void)
 
 	/* Init a new repo */
 	cl_set_cleanup(&cleanup_repository, "not.overwrite.git");
-	cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1));
+	cl_git_pass(git_repository_init(&g_repo, "not.overwrite.git", 1));
 
 	/* Change the "core.ignorecase" config value to something unlikely */
-	git_repository_config(&config, _repo);
+	git_repository_config(&config, g_repo);
 	git_config_set_int32(config, "core.ignorecase", 42);
 	git_config_free(config);
-	git_repository_free(_repo);
-	_repo = NULL;
+	git_repository_free(g_repo);
+	g_repo = NULL;
 
 	/* Reinit the repository */
-	cl_git_pass(git_repository_init(&_repo, "not.overwrite.git", 1));
-	git_repository_config(&config, _repo);
+	cl_git_pass(git_repository_init(&g_repo, "not.overwrite.git", 1));
+	git_repository_config(&config, g_repo);
 
 	/* Ensure the "core.ignorecase" config value hasn't been updated */
 	cl_git_pass(git_config_get_int32(&current_value, config, "core.ignorecase"));
@@ -350,26 +357,26 @@ void test_repo_init__reinit_overwrites_filemode(void)
 
 	/* Init a new repo */
 	cl_set_cleanup(&cleanup_repository, "overwrite.git");
-	cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
+	cl_git_pass(git_repository_init(&g_repo, "overwrite.git", 1));
 
 	/* Change the "core.filemode" config value to something unlikely */
-	cl_repo_set_bool(_repo, "core.filemode", !expected);
+	cl_repo_set_bool(g_repo, "core.filemode", !expected);
 
-	git_repository_free(_repo);
-	_repo = NULL;
+	git_repository_free(g_repo);
+	g_repo = NULL;
 
 	/* Reinit the repository */
-	cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1));
+	cl_git_pass(git_repository_init(&g_repo, "overwrite.git", 1));
 
 	/* Ensure the "core.filemode" config value has been reset */
-	current_value = cl_repo_get_bool(_repo, "core.filemode");
+	current_value = cl_repo_get_bool(g_repo, "core.filemode");
 	cl_assert_equal_i(expected, current_value);
 }
 
 void test_repo_init__sets_logAllRefUpdates_according_to_type_of_repository(void)
 {
 	assert_config_entry_on_init_bytype("core.logallrefupdates", GIT_ENOTFOUND, true);
-	git_repository_free(_repo);
+	git_repository_free(g_repo);
 	assert_config_entry_on_init_bytype("core.logallrefupdates", true, false);
 }
 
@@ -378,16 +385,16 @@ void test_repo_init__extended_0(void)
 	git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
 
 	/* without MKDIR this should fail */
-	cl_git_fail(git_repository_init_ext(&_repo, "extended", &opts));
+	cl_git_fail(git_repository_init_ext(&g_repo, "extended", &opts));
 
 	/* make the directory first, then it should succeed */
 	cl_git_pass(git_futils_mkdir("extended", 0775, 0));
-	cl_git_pass(git_repository_init_ext(&_repo, "extended", &opts));
+	cl_git_pass(git_repository_init_ext(&g_repo, "extended", &opts));
 
-	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/extended/"));
-	cl_assert(!git__suffixcmp(git_repository_path(_repo), "/extended/.git/"));
-	cl_assert(!git_repository_is_bare(_repo));
-	cl_assert(git_repository_is_empty(_repo));
+	cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "/extended/"));
+	cl_assert(!git__suffixcmp(git_repository_path(g_repo), "/extended/.git/"));
+	cl_assert(!git_repository_is_bare(g_repo));
+	cl_assert(git_repository_is_empty(g_repo));
 
 	cleanup_repository("extended");
 }
@@ -407,33 +414,33 @@ void test_repo_init__extended_1(void)
 	opts.initial_head = "development";
 	opts.origin_url = "https://github.com/libgit2/libgit2.git";
 
-	cl_git_pass(git_repository_init_ext(&_repo, "root/b/c.git", &opts));
+	cl_git_pass(git_repository_init_ext(&g_repo, "root/b/c.git", &opts));
 
-	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "/c_wd/"));
-	cl_assert(!git__suffixcmp(git_repository_path(_repo), "/c.git/"));
+	cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "/c_wd/"));
+	cl_assert(!git__suffixcmp(git_repository_path(g_repo), "/c.git/"));
 	cl_assert(git_path_isfile("root/b/c_wd/.git"));
-	cl_assert(!git_repository_is_bare(_repo));
+	cl_assert(!git_repository_is_bare(g_repo));
 	/* repo will not be counted as empty because we set head to "development" */
-	cl_assert(!git_repository_is_empty(_repo));
+	cl_assert(!git_repository_is_empty(g_repo));
 
-	cl_git_pass(git_path_lstat(git_repository_path(_repo), &st));
+	cl_git_pass(git_path_lstat(git_repository_path(g_repo), &st));
 	cl_assert(S_ISDIR(st.st_mode));
 	if (cl_is_chmod_supported())
 		cl_assert((S_ISGID & st.st_mode) == S_ISGID);
 	else
 		cl_assert((S_ISGID & st.st_mode) == 0);
 
-	cl_git_pass(git_reference_lookup(&ref, _repo, "HEAD"));
+	cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
 	cl_assert(git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC);
 	cl_assert_equal_s("refs/heads/development", git_reference_symbolic_target(ref));
 	git_reference_free(ref);
 
-	cl_git_pass(git_remote_lookup(&remote, _repo, "origin"));
+	cl_git_pass(git_remote_lookup(&remote, g_repo, "origin"));
 	cl_assert_equal_s("origin", git_remote_name(remote));
 	cl_assert_equal_s(opts.origin_url, git_remote_url(remote));
 	git_remote_free(remote);
 
-	git_repository_free(_repo);
+	git_repository_free(g_repo);
 	cl_fixture_cleanup("root");
 }
 
@@ -449,17 +456,17 @@ void test_repo_init__relative_gitdir(void)
 		GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
 
 	/* make the directory first, then it should succeed */
-	cl_git_pass(git_repository_init_ext(&_repo, "root/b/my_repository", &opts));
+	cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));
 
-	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "root/b/c_wd/"));
-	cl_assert(!git__suffixcmp(git_repository_path(_repo), "root/b/my_repository/"));
-	cl_assert(!git_repository_is_bare(_repo));
-	cl_assert(git_repository_is_empty(_repo));
+	cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "root/b/c_wd/"));
+	cl_assert(!git__suffixcmp(git_repository_path(g_repo), "root/b/my_repository/"));
+	cl_assert(!git_repository_is_bare(g_repo));
+	cl_assert(git_repository_is_empty(g_repo));
 
 	/* Verify that the gitlink and worktree entries are relative */
 
 	/* Verify worktree */
-	assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
+	assert_config_entry_value(g_repo, "core.worktree", "../c_wd/");
 
 	/* Verify gitlink */
 	cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
@@ -485,18 +492,18 @@ void test_repo_init__relative_gitdir_2(void)
 		GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
 
 	/* make the directory first, then it should succeed */
-	cl_git_pass(git_repository_init_ext(&_repo, "root/b/my_repository", &opts));
+	cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));
 	git_buf_dispose(&full_path);
 
-	cl_assert(!git__suffixcmp(git_repository_workdir(_repo), "root/b/c_wd/"));
-	cl_assert(!git__suffixcmp(git_repository_path(_repo), "root/b/my_repository/"));
-	cl_assert(!git_repository_is_bare(_repo));
-	cl_assert(git_repository_is_empty(_repo));
+	cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "root/b/c_wd/"));
+	cl_assert(!git__suffixcmp(git_repository_path(g_repo), "root/b/my_repository/"));
+	cl_assert(!git_repository_is_bare(g_repo));
+	cl_assert(git_repository_is_empty(g_repo));
 
 	/* Verify that the gitlink and worktree entries are relative */
 
 	/* Verify worktree */
-	assert_config_entry_value(_repo, "core.worktree", "../c_wd/");
+	assert_config_entry_value(g_repo, "core.worktree", "../c_wd/");
 
 	/* Verify gitlink */
 	cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
@@ -513,11 +520,11 @@ void test_repo_init__can_reinit_an_initialized_repository(void)
 	cl_set_cleanup(&cleanup_repository, "extended");
 
 	cl_git_pass(git_futils_mkdir("extended", 0775, 0));
-	cl_git_pass(git_repository_init(&_repo, "extended", false));
+	cl_git_pass(git_repository_init(&g_repo, "extended", false));
 
 	cl_git_pass(git_repository_init(&reinit, "extended", false));
 
-	cl_assert_equal_s(git_repository_path(_repo), git_repository_path(reinit));
+	cl_assert_equal_s(git_repository_path(g_repo), git_repository_path(reinit));
 
 	git_repository_free(reinit);
 }
@@ -529,10 +536,10 @@ void test_repo_init__init_with_initial_commit(void)
 	cl_set_cleanup(&cleanup_repository, "committed");
 
 	/* Initialize the repository */
-	cl_git_pass(git_repository_init(&_repo, "committed", 0));
+	cl_git_pass(git_repository_init(&g_repo, "committed", 0));
 
 	/* Index will be automatically created when requested for a new repo */
-	cl_git_pass(git_repository_index(&index, _repo));
+	cl_git_pass(git_repository_index(&index, g_repo));
 
 	/* Create a file so we can commit it
 	 *
@@ -558,7 +565,7 @@ void test_repo_init__init_with_initial_commit(void)
 	/* Make sure we're ready to use git_signature_default :-) */
 	{
 		git_config *cfg, *local;
-		cl_git_pass(git_repository_config(&cfg, _repo));
+		cl_git_pass(git_repository_config(&cfg, g_repo));
 		cl_git_pass(git_config_open_level(&local, cfg, GIT_CONFIG_LEVEL_LOCAL));
 		cl_git_pass(git_config_set_string(local, "user.name", "Test User"));
 		cl_git_pass(git_config_set_string(local, "user.email", "t@example.com"));
@@ -572,12 +579,12 @@ void test_repo_init__init_with_initial_commit(void)
 		git_oid tree_id, commit_id;
 		git_tree *tree;
 
-		cl_git_pass(git_signature_default(&sig, _repo));
+		cl_git_pass(git_signature_default(&sig, g_repo));
 		cl_git_pass(git_index_write_tree(&tree_id, index));
-		cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
+		cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
 
 		cl_git_pass(git_commit_create_v(
-			&commit_id, _repo, "HEAD", sig, sig,
+			&commit_id, g_repo, "HEAD", sig, sig,
 			NULL, "First", tree, 0));
 
 		git_tree_free(tree);
@@ -674,8 +681,8 @@ void test_repo_init__defaultbranch_config(void)
 
 	create_tmp_global_config("tmp_global_path", "init.defaultbranch", "my_default_branch");
 
-	cl_git_pass(git_repository_init(&_repo, "repo", 0));
-	cl_git_pass(git_reference_lookup(&head, _repo, "HEAD"));
+	cl_git_pass(git_repository_init(&g_repo, "repo", 0));
+	cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
 
 	cl_assert_equal_s("refs/heads/my_default_branch", git_reference_symbolic_target(head));
 
diff --git a/tests/trace/windows/stacktrace.c b/tests/trace/windows/stacktrace.c
index 756ac68..34fcbcb 100644
--- a/tests/trace/windows/stacktrace.c
+++ b/tests/trace/windows/stacktrace.c
@@ -58,47 +58,48 @@ void test_trace_windows_stacktrace__leaks(void)
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"p1");
-	cl_assert((leaks == 1));
+	cl_assert_equal_i(1, leaks);
 
 	p2 = git__malloc(5);
 	leaks = git_win32__crtdbg_stacktrace__dump(
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"p1,p2");
-	cl_assert((leaks == 2));
+	cl_assert_equal_i(2, leaks);
 
 	p3 = git__malloc(5);
 	leaks = git_win32__crtdbg_stacktrace__dump(
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"p1,p2,p3");
-	cl_assert((leaks == 3));
+	cl_assert_equal_i(3, leaks);
 
 	git__free(p2);
 	leaks = git_win32__crtdbg_stacktrace__dump(
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"p1,p3");
-	cl_assert((leaks == 2));
+	cl_assert_equal_i(2, leaks);
 
 	/* move the mark. only new leaks should appear afterwards */
 	error = git_win32__crtdbg_stacktrace__dump(
 		GIT_WIN32__CRTDBG_STACKTRACE__SET_MARK,
 		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(
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"not_p1,not_p3");
-	cl_assert((leaks == 0));
+	cl_assert_equal_i(0, leaks);
 
 	p4 = git__malloc(5);
 	leaks = git_win32__crtdbg_stacktrace__dump(
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"p4,not_p1,not_p3");
-	cl_assert((leaks == 1));
+	cl_assert_equal_i(1, leaks);
 
 	git__free(p1);
 	git__free(p3);
@@ -106,21 +107,21 @@ void test_trace_windows_stacktrace__leaks(void)
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"p4");
-	cl_assert((leaks == 1));
+	cl_assert_equal_i(1, leaks);
 
 	git__free(p4);
 	leaks = git_win32__crtdbg_stacktrace__dump(
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_SINCE_MARK,
 		"end");
-	cl_assert((leaks == 0));
+	cl_assert_equal_i(0, leaks);
 
 	/* confirm current absolute leaks count matches beginning value. */
 	after = git_win32__crtdbg_stacktrace__dump(
 		GIT_WIN32__CRTDBG_STACKTRACE__QUIET |
 		GIT_WIN32__CRTDBG_STACKTRACE__LEAKS_TOTAL,
 		"total");
-	cl_assert((before == after));
+	cl_assert_equal_i(before, after);
 #endif
 }