path: root/repository.c
diff options
authorNguyễn Thái Ngọc Duy <>2018-05-10 06:13:10 (GMT)
committerJunio C Hamano <>2018-05-10 09:33:09 (GMT)
commit74373b5f10e2e8720ad2ae8211811757601550fd (patch)
treee1052290a093b3790bed21da2ed78fccc37deee1 /repository.c
parent3013dff8662eae06457fe6e5348dfe2270810ab2 (diff)
repository: fix free problem with repo_clear(the_repository)
the_repository is special. One of the special things about it is that it does not allocate a new index_state object like submodules but points to the global the_index variable instead. As a global variable, the_index cannot be free()'d. Add an exception for this in repo_clear(). In the future perhaps we would be able to allocate the_repository's index on heap too. Then we can revert this. the_repository->index remains pointed to a clean the_index even after repo_clear() so that it could still be used next time (e.g. in a crazy use case where a dev switches repo in the same process). Signed-off-by: Nguyễn Thái Ngọc Duy <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'repository.c')
1 files changed, 2 insertions, 1 deletions
diff --git a/repository.c b/repository.c
index bb2fae5..450852d 100644
--- a/repository.c
+++ b/repository.c
@@ -220,7 +220,8 @@ void repo_clear(struct repository *repo)
if (repo->index) {
- FREE_AND_NULL(repo->index);
+ if (repo->index != &the_index)
+ FREE_AND_NULL(repo->index);