Skip to content

Commit da635ed

Browse files
committed
tests: move free functions at the end
1 parent ebe5d8e commit da635ed

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

tests/refs/reflog/messages.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ void test_refs_reflog_messages__branch_birth(void)
156156

157157
cl_git_pass(git_repository_head(&ref, g_repo));
158158
cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
159-
git_reference_free(ref);
160159

161160
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/orphan"));
162161

@@ -167,53 +166,53 @@ void test_refs_reflog_messages__branch_birth(void)
167166
msg = "message 2";
168167
cl_git_pass(git_commit_create(&id, g_repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
169168

170-
git_tree_free(tree);
171-
172169
cl_assert_equal_i(1, reflog_entrycount(g_repo, "refs/heads/orphan"));
173170

174171
nentries_after = reflog_entrycount(g_repo, GIT_HEAD_FILE);
175172

176173
cl_assert_equal_i(nentries + 1, nentries_after);
177174

178175
git_signature_free(sig);
176+
git_tree_free(tree);
177+
git_reference_free(ref);
179178
}
180179

181180
void test_refs_reflog_messages__commit_on_symbolic_ref_updates_head_reflog(void)
182181
{
183182
git_signature *sig;
184183
git_oid id;
185184
git_tree *tree;
186-
git_reference *ref;
185+
git_reference *ref1, *ref2;
187186
const char *msg;
188187
size_t nentries_head, nentries_master;
189188

190189
nentries_head = reflog_entrycount(g_repo, GIT_HEAD_FILE);
191190

192191
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
193192

194-
cl_git_pass(git_repository_head(&ref, g_repo));
195-
cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
196-
git_reference_free(ref);
193+
cl_git_pass(git_repository_head(&ref1, g_repo));
194+
cl_git_pass(git_reference_peel((git_object **) &tree, ref1, GIT_OBJ_TREE));
197195

198196
nentries_master = reflog_entrycount(g_repo, "refs/heads/master");
199197

200198
msg = "message 1";
201-
cl_git_pass(git_reference_symbolic_create(&ref, g_repo, "refs/heads/master", "refs/heads/foo", 1, msg));
202-
git_reference_free(ref);
199+
cl_git_pass(git_reference_symbolic_create(&ref2, g_repo, "refs/heads/master", "refs/heads/foo", 1, msg));
203200

204201
cl_assert_equal_i(0, reflog_entrycount(g_repo, "refs/heads/foo"));
205202
cl_assert_equal_i(nentries_head, reflog_entrycount(g_repo, GIT_HEAD_FILE));
206203
cl_assert_equal_i(nentries_master, reflog_entrycount(g_repo, "refs/heads/master"));
207204

208205
msg = "message 2";
209206
cl_git_pass(git_commit_create(&id, g_repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
210-
git_tree_free(tree);
211207

212208
cl_assert_equal_i(1, reflog_entrycount(g_repo, "refs/heads/foo"));
213209
cl_assert_equal_i(nentries_head + 1, reflog_entrycount(g_repo, GIT_HEAD_FILE));
214210
cl_assert_equal_i(nentries_master, reflog_entrycount(g_repo, "refs/heads/master"));
215211

216212
git_signature_free(sig);
213+
git_reference_free(ref1);
214+
git_reference_free(ref2);
215+
git_tree_free(tree);
217216
}
218217

219218
void test_refs_reflog_messages__show_merge_for_merge_commits(void)
@@ -331,13 +330,13 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
331330
git_annotated_commit *annotated;
332331
git_object *obj;
333332
git_commit *target;
334-
git_reference *branch;
333+
git_reference *branch1, *branch2;
335334

336335
cl_git_pass(git_revparse_single(&obj, g_repo, "e90810b8df3"));
337336
cl_git_pass(git_commit_lookup(&target, g_repo, git_object_id(obj)));
338337
git_object_free(obj);
339338

340-
cl_git_pass(git_branch_create(&branch, g_repo, NEW_BRANCH_NAME, target, false));
339+
cl_git_pass(git_branch_create(&branch1, g_repo, NEW_BRANCH_NAME, target, false));
341340

342341
cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
343342
cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
@@ -346,11 +345,9 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
346345
g_email, git_buf_cstr(&buf));
347346

348347
cl_git_pass(git_reference_remove(g_repo, "refs/heads/" NEW_BRANCH_NAME));
349-
git_reference_free(branch);
350-
git_buf_clear(&buf);
351348

352349
cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3"));
353-
cl_git_pass(git_branch_create_from_annotated(&branch, g_repo, NEW_BRANCH_NAME, annotated, true));
350+
cl_git_pass(git_branch_create_from_annotated(&branch2, g_repo, NEW_BRANCH_NAME, annotated, true));
354351

355352
cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
356353
GIT_OID_HEX_ZERO,
@@ -359,6 +356,9 @@ void test_refs_reflog_messages__creating_branches_default_messages(void)
359356

360357
git_annotated_commit_free(annotated);
361358
git_buf_free(&buf);
359+
git_commit_free(target);
360+
git_reference_free(branch1);
361+
git_reference_free(branch2);
362362
}
363363

364364
void test_refs_reflog_messages__moving_branch_default_message(void)
@@ -397,12 +397,13 @@ void test_refs_reflog_messages__detaching_head_default_message(void)
397397
/* take the repo back to its original state */
398398
cl_git_pass(git_reference_symbolic_create(&ref, g_repo, "HEAD", "refs/heads/master",
399399
true, "REATTACH"));
400-
git_reference_free(ref);
401400

402401
cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
403402
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
404403
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
405404
NULL, "REATTACH");
406405

407406
cl_assert_equal_i(false, git_repository_head_detached(g_repo));
407+
408+
git_reference_free(ref);
408409
}

0 commit comments

Comments
 (0)