Skip to content

Commit 74373b5

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3013dff commit 74373b5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

repository.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ void repo_clear(struct repository *repo)
220220

221221
if (repo->index) {
222222
discard_index(repo->index);
223-
FREE_AND_NULL(repo->index);
223+
if (repo->index != &the_index)
224+
FREE_AND_NULL(repo->index);
224225
}
225226
}
226227

0 commit comments

Comments
 (0)