{"thread":{"id":"46868","subject":"[PATCH] repository: use FREE_AND_NULL","startedAt":"2017-10-01T14:44:57Z","lastAt":"2017-10-01T14:44:57Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"329283","messageId":"503c157c-70c8-7902-6170-3847c39ab0e0@web.de","threadId":"46868","inReplyTo":null,"subject":"[PATCH] repository: use FREE_AND_NULL","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-10-01T14:44:46Z","receivedAt":"2017-10-01T14:44:57Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Use the macro FREE_AND_NULL to release allocated objects and clear their\npointers.  This is shorter and documents the intent better by combining\nthe two related operations into one.\n\nPatch generated with Coccinelle and contrib/coccinelle/free.cocci.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n repository.c | 27 +++++++++------------------\n 1 file changed, 9 insertions(+), 18 deletions(-)\n\ndiff --git a/repository.c b/repository.c\nindex 97c732bd48..bb2fae5446 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -200,25 +200,17 @@ int repo_submodule_init(struct repository *submodule,\n \n void repo_clear(struct repository *repo)\n {\n-\tfree(repo->gitdir);\n-\trepo->gitdir = NULL;\n-\tfree(repo->commondir);\n-\trepo->commondir = NULL;\n-\tfree(repo->objectdir);\n-\trepo->objectdir = NULL;\n-\tfree(repo->graft_file);\n-\trepo->graft_file = NULL;\n-\tfree(repo->index_file);\n-\trepo->index_file = NULL;\n-\tfree(repo->worktree);\n-\trepo->worktree = NULL;\n-\tfree(repo->submodule_prefix);\n-\trepo->submodule_prefix = NULL;\n+\tFREE_AND_NULL(repo->gitdir);\n+\tFREE_AND_NULL(repo->commondir);\n+\tFREE_AND_NULL(repo->objectdir);\n+\tFREE_AND_NULL(repo->graft_file);\n+\tFREE_AND_NULL(repo->index_file);\n+\tFREE_AND_NULL(repo->worktree);\n+\tFREE_AND_NULL(repo->submodule_prefix);\n \n \tif (repo->config) {\n \t\tgit_configset_clear(repo->config);\n-\t\tfree(repo->config);\n-\t\trepo->config = NULL;\n+\t\tFREE_AND_NULL(repo->config);\n \t}\n \n \tif (repo->submodule_cache) {\n@@ -228,8 +220,7 @@ void repo_clear(struct repository *repo)\n \n \tif (repo->index) {\n \t\tdiscard_index(repo->index);\n-\t\tfree(repo->index);\n-\t\trepo->index = NULL;\n+\t\tFREE_AND_NULL(repo->index);\n \t}\n }\n \n-- \n2.14.2\n"}]}