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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 1, 2017 at 16:44 UTC
90dd04aaeb9ddbdc26c5937a118db505c6a28394
1 file changed
+9
-18
repository.c
+9
-18
@@ -200,25 +200,17 @@ out:
200
201
void repo_clear(struct repository *repo)
202
{
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);
210
211
if (repo->config) {
212
git_configset_clear(repo->config);
220
- free(repo->config);
221
- repo->config = NULL;
213
+ FREE_AND_NULL(repo->config);
214
}
215
216
if (repo->submodule_cache) {
@@ -228,8 +220,7 @@ void repo_clear(struct repository *repo)
220
221
if (repo->index) {
222
discard_index(repo->index);
231
- free(repo->index);
232
- repo->index = NULL;
223
+ FREE_AND_NULL(repo->index);
224
}
225
}
226