Skip to content

Commit ecd55ce

Browse files
authored
Merge pull request libgit2#4477 from pks-t/pks/memleaks
Memory leaks
2 parents f1323d9 + 782402c commit ecd55ce

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

include/git2/refs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ typedef int (*git_reference_foreach_name_cb)(const char *name, void *payload);
433433
* passed to this method. Returning a non-zero value from the callback
434434
* will terminate the iteration.
435435
*
436+
* Note that the callback function is responsible to call `git_reference_free`
437+
* on each reference passed to it.
438+
*
436439
* @param repo Repository where to find the refs
437440
* @param callback Function which will be called for every listed ref
438441
* @param payload Additional data to pass to the callback

src/transports/local.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ static int foreach_reference_cb(git_reference *reference, void *payload)
519519
error = 0;
520520
}
521521

522+
git_reference_free(reference);
523+
522524
return error;
523525
}
524526

tests/network/fetchlocal.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,6 @@ void test_network_fetchlocal__prune_tag(void)
314314
git_repository_free(repo);
315315
}
316316

317-
static void cleanup_sandbox(void *unused)
318-
{
319-
GIT_UNUSED(unused);
320-
cl_git_sandbox_cleanup();
321-
}
322-
323317
void test_network_fetchlocal__partial(void)
324318
{
325319
git_repository *repo = cl_git_sandbox_init("partial-testrepo");
@@ -332,7 +326,6 @@ void test_network_fetchlocal__partial(void)
332326
options.callbacks.transfer_progress = transfer_cb;
333327
options.callbacks.payload = &callcount;
334328

335-
cl_set_cleanup(&cleanup_sandbox, NULL);
336329
cl_git_pass(git_reference_list(&refnames, repo));
337330
cl_assert_equal_i(1, (int)refnames.count);
338331

@@ -420,7 +413,6 @@ void test_network_fetchlocal__multi_remotes(void)
420413
git_strarray refnames = {0};
421414
git_fetch_options options = GIT_FETCH_OPTIONS_INIT;
422415

423-
cl_set_cleanup(&cleanup_sandbox, NULL);
424416
options.callbacks.transfer_progress = transfer_cb;
425417
cl_git_pass(git_remote_set_url(repo, "test", cl_git_fixture_url("testrepo.git")));
426418
cl_git_pass(git_remote_lookup(&test, repo, "test"));

tests/refs/iterator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ void test_refs_iterator__foreach_name(void)
213213
git_vector_foreach(&output, i, name) {
214214
cl_assert(refnames[i] != NULL);
215215
cl_assert_equal_s(refnames[i], name);
216+
git__free(name);
216217
}
217218

218219
git_vector_free(&output);

0 commit comments

Comments
 (0)