Commit Diff


commit - 8f74b4995a14ceab9270fcd22a5c1ca34c5cc3be
commit + d0bb0ed648b2dd60e628937450cbaf9200beb9a6
blob - e7220dfb5d8df045791b203031fa93e74e05b407
blob + 488dc79c339ccc7d9f24681ea94bbf19ab7b4309
--- got/got.c
+++ got/got.c
@@ -2995,7 +2995,7 @@ checkout_ancestry_error(struct got_reference *ref, con
 static const struct got_error *
 cmd_checkout(int argc, char *argv[])
 {
-	const struct got_error *error = NULL;
+	const struct got_error *close_err, *error = NULL;
 	struct got_repository *repo = NULL;
 	struct got_reference *head_ref = NULL, *ref = NULL;
 	struct got_worktree *worktree = NULL;
@@ -3251,7 +3251,12 @@ done:
 	if (ref)
 		got_ref_close(ref);
 	if (repo) {
-		const struct got_error *close_err = got_repo_close(repo);
+		close_err = got_repo_close(repo);
+		if (error == NULL)
+			error = close_err;
+	}
+	if (worktree != NULL) {
+		close_err = got_worktree_close(worktree);
 		if (error == NULL)
 			error = close_err;
 	}
@@ -3512,7 +3517,7 @@ wrap_not_worktree_error(const struct got_error *orig_e
 static const struct got_error *
 cmd_update(int argc, char *argv[])
 {
-	const struct got_error *error = NULL;
+	const struct got_error *close_err, *error = NULL;
 	struct got_repository *repo = NULL;
 	struct got_worktree *worktree = NULL;
 	char *worktree_path = NULL;
@@ -3707,10 +3712,15 @@ done:
 			error = pack_err;
 	}
 	if (repo) {
-		const struct got_error *close_err = got_repo_close(repo);
+		close_err = got_repo_close(repo);
 		if (error == NULL)
 			error = close_err;
 	}
+	if (worktree != NULL) {
+		close_err = got_worktree_close(worktree);
+		if (error == NULL)
+			error = close_err;
+	}
 	if (head_ref != NULL)
 		got_ref_close(head_ref);
 	free(worktree_path);