Skip to content

Commit 1a7e5ef

Browse files
pks-tgitster
authored andcommitted
submodule: fix leaking fetch tasks
When done with a fetch task used for parallel fetches of submodules, we need to both call `fetch_task_release()` to release the task's contents and `free()` to release the task itself. Most sites do this already, but some only call `fetch_task_release()` and thus leak memory. While we could trivially fix this by adding the two missing calls to free(3P), the result would be that we always call both functions. Let's thus refactor the code such that `fetch_task_release()` also frees the structure itself. Rename it to `fetch_task_free()` accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c369fc4 commit 1a7e5ef

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

submodule.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ static const struct submodule *get_non_gitmodules_submodule(const char *path)
14961496
return (const struct submodule *) ret;
14971497
}
14981498

1499-
static void fetch_task_release(struct fetch_task *p)
1499+
static void fetch_task_free(struct fetch_task *p)
15001500
{
15011501
if (p->free_sub)
15021502
free((void*)p->sub);
@@ -1508,6 +1508,7 @@ static void fetch_task_release(struct fetch_task *p)
15081508
FREE_AND_NULL(p->repo);
15091509

15101510
strvec_clear(&p->git_args);
1511+
free(p);
15111512
}
15121513

15131514
static struct repository *get_submodule_repo_for(struct repository *r,
@@ -1576,8 +1577,7 @@ static struct fetch_task *fetch_task_create(struct submodule_parallel_fetch *spf
15761577
return task;
15771578

15781579
cleanup:
1579-
fetch_task_release(task);
1580-
free(task);
1580+
fetch_task_free(task);
15811581
return NULL;
15821582
}
15831583

@@ -1607,8 +1607,7 @@ get_fetch_task_from_index(struct submodule_parallel_fetch *spf,
16071607
} else {
16081608
struct strbuf empty_submodule_path = STRBUF_INIT;
16091609

1610-
fetch_task_release(task);
1611-
free(task);
1610+
fetch_task_free(task);
16121611

16131612
/*
16141613
* An empty directory is normal,
@@ -1654,8 +1653,7 @@ get_fetch_task_from_changed(struct submodule_parallel_fetch *spf,
16541653
cs_data->path,
16551654
repo_find_unique_abbrev(the_repository, cs_data->super_oid, DEFAULT_ABBREV));
16561655

1657-
fetch_task_release(task);
1658-
free(task);
1656+
fetch_task_free(task);
16591657
continue;
16601658
}
16611659

@@ -1763,7 +1761,7 @@ static int fetch_start_failure(struct strbuf *err UNUSED,
17631761

17641762
spf->result = 1;
17651763

1766-
fetch_task_release(task);
1764+
fetch_task_free(task);
17671765
return 0;
17681766
}
17691767

@@ -1828,8 +1826,7 @@ static int fetch_finish(int retvalue, struct strbuf *err UNUSED,
18281826
}
18291827

18301828
out:
1831-
fetch_task_release(task);
1832-
1829+
fetch_task_free(task);
18331830
return 0;
18341831
}
18351832

0 commit comments

Comments
 (0)