checkout: die_if_checked_out: simplify strbuf management
There is no reason to keep the strbuf active long after its last use. By releasing it as early as possible, resource management is simplified and there is less worry about future changes resulting in a leak. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Jul 17, 2015 at 18:59 UTC
4e07815dba5ccad0cfcb672b99e2000bd3dc3543
1 file changed
+3
-4
builtin/checkout.c
+3
-4
@@ -924,17 +924,16 @@ static void die_if_checked_out(struct branch_info *new)
924
check_linked_checkout(new, NULL);
925
926
strbuf_addf(&path, "%s/worktrees", get_git_common_dir());
927
- if ((dir = opendir(path.buf)) == NULL) {
928
- strbuf_release(&path);
927
+ dir = opendir(path.buf);
928
+ strbuf_release(&path);
929
+ if (!dir)
930
return;
930
- }
931
932
while ((d = readdir(dir)) != NULL) {
933
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
934
continue;
935
check_linked_checkout(new, d->d_name);
936
}
937
- strbuf_release(&path);
937
closedir(dir);
938
}
939