aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/scalar/scalar.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-07-05 15:46:59 +0200
committerJunio C Hamano <gitster@pobox.com>2022-07-06 12:24:43 -0700
commit4f40f6cb7365889b262aa93871964f70c91a9ebc (patch)
tree08640c84f6f2f5a86bbe0decd609cb140531d305 /contrib/scalar/scalar.c
parent7a9a10b10e2f14ffb7c17e59f147186f85a2a94e (diff)
downloadgit-4f40f6cb7365889b262aa93871964f70c91a9ebc.tar.gz
cocci: add and apply a rule to find "unused" strbufs
Add a coccinelle rule to remove "struct strbuf" initialization followed by calling "strbuf_release()" function, without any uses of the strbuf in the same function. See the tests in contrib/coccinelle/tests/unused.{c,res} for what it's intended to find and replace. The inclusion of "contrib/scalar/scalar.c" is because "spatch" was manually run on it (we don't usually run spatch on contrib). Per the "buggy code" comment we also match a strbuf_init() before the xmalloc(), but we're not seeking to be so strict as to make checks that the compiler will catch for us redundant. Saying we'll match either "init" or "xmalloc" lines makes the rule simpler. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/scalar/scalar.c')
-rw-r--r--contrib/scalar/scalar.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c
index 28176914e5..97e71fe19c 100644
--- a/contrib/scalar/scalar.c
+++ b/contrib/scalar/scalar.c
@@ -687,7 +687,7 @@ static int cmd_diagnose(int argc, const char **argv)
int stdout_fd = -1, archiver_fd = -1;
time_t now = time(NULL);
struct tm tm;
- struct strbuf path = STRBUF_INIT, buf = STRBUF_INIT;
+ struct strbuf buf = STRBUF_INIT;
int res = 0;
argc = parse_options(argc, argv, NULL, options,
@@ -779,7 +779,6 @@ diagnose_cleanup:
free(argv_copy);
strvec_clear(&archiver_args);
strbuf_release(&zip_path);
- strbuf_release(&path);
strbuf_release(&buf);
return res;