Skip to content

Commit 4e07815

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aaad2c9 commit 4e07815

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

builtin/checkout.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,17 +924,16 @@ static void die_if_checked_out(struct branch_info *new)
924924
check_linked_checkout(new, NULL);
925925

926926
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)
929930
return;
930-
}
931931

932932
while ((d = readdir(dir)) != NULL) {
933933
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
934934
continue;
935935
check_linked_checkout(new, d->d_name);
936936
}
937-
strbuf_release(&path);
938937
closedir(dir);
939938
}
940939

0 commit comments

Comments
 (0)