aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2015-07-17 18:59:59 -0400
committerJunio C Hamano <gitster@pobox.com>2015-07-20 11:29:24 -0700
commit4e07815dba5ccad0cfcb672b99e2000bd3dc3543 (patch)
treea5ba2f603431a4c60649911a1f53d1fb5ea4d6aa
parentaaad2c948f11cd57348135fb1e62b012db716182 (diff)
downloadgit-4e07815dba5ccad0cfcb672b99e2000bd3dc3543.tar.gz
git-4e07815dba5ccad0cfcb672b99e2000bd3dc3543.tar.xz
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>
-rw-r--r--builtin/checkout.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 1992c41d4..c36bf8acf 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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);
}