Skip to content

Commit

Permalink
checkout: die_if_checked_out: simplify strbuf management
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Sunshine authored and Junio C Hamano committed Jul 20, 2015
1 parent aaad2c9 commit 4e07815
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,17 +924,16 @@ static void die_if_checked_out(struct branch_info *new)
check_linked_checkout(new, NULL);

strbuf_addf(&path, "%s/worktrees", get_git_common_dir());
if ((dir = opendir(path.buf)) == NULL) {
strbuf_release(&path);
dir = opendir(path.buf);
strbuf_release(&path);
if (!dir)
return;
}

while ((d = readdir(dir)) != NULL) {
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
continue;
check_linked_checkout(new, d->d_name);
}
strbuf_release(&path);
closedir(dir);
}

Expand Down

0 comments on commit 4e07815

Please sign in to comment.