Skip to content

Commit 90dd04a

Browse files
rscharfegitster
authored andcommitted
repository: use FREE_AND_NULL
Use the macro FREE_AND_NULL to release allocated objects and clear their pointers. This is shorter and documents the intent better by combining the two related operations into one. Patch generated with Coccinelle and contrib/coccinelle/free.cocci. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ea220ee commit 90dd04a

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

repository.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,17 @@ int repo_submodule_init(struct repository *submodule,
200200

201201
void repo_clear(struct repository *repo)
202202
{
203-
free(repo->gitdir);
204-
repo->gitdir = NULL;
205-
free(repo->commondir);
206-
repo->commondir = NULL;
207-
free(repo->objectdir);
208-
repo->objectdir = NULL;
209-
free(repo->graft_file);
210-
repo->graft_file = NULL;
211-
free(repo->index_file);
212-
repo->index_file = NULL;
213-
free(repo->worktree);
214-
repo->worktree = NULL;
215-
free(repo->submodule_prefix);
216-
repo->submodule_prefix = NULL;
203+
FREE_AND_NULL(repo->gitdir);
204+
FREE_AND_NULL(repo->commondir);
205+
FREE_AND_NULL(repo->objectdir);
206+
FREE_AND_NULL(repo->graft_file);
207+
FREE_AND_NULL(repo->index_file);
208+
FREE_AND_NULL(repo->worktree);
209+
FREE_AND_NULL(repo->submodule_prefix);
217210

218211
if (repo->config) {
219212
git_configset_clear(repo->config);
220-
free(repo->config);
221-
repo->config = NULL;
213+
FREE_AND_NULL(repo->config);
222214
}
223215

224216
if (repo->submodule_cache) {
@@ -228,8 +220,7 @@ void repo_clear(struct repository *repo)
228220

229221
if (repo->index) {
230222
discard_index(repo->index);
231-
free(repo->index);
232-
repo->index = NULL;
223+
FREE_AND_NULL(repo->index);
233224
}
234225
}
235226

0 commit comments

Comments
 (0)