using a local packfd variable in open_worktree() is sufficient
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/lib/got_lib_worktree.h b/lib/got_lib_worktree.h
index 414cf45..a358845 100644
--- a/lib/got_lib_worktree.h
+++ b/lib/got_lib_worktree.h
@@ -22,7 +22,6 @@ struct got_worktree {
struct got_object_id *base_commit_id;
char *head_ref_name;
uuid_t uuid;
- int *pack_fds;
/*
* File descriptor for the lock file, open while a work tree is open.
diff --git a/lib/worktree_open.c b/lib/worktree_open.c
index 8178c5f..529f4b6 100644
--- a/lib/worktree_open.c
+++ b/lib/worktree_open.c
@@ -116,6 +116,7 @@ open_worktree(struct got_worktree **worktree, const char *path)
int version, fd = -1;
const char *errstr;
struct got_repository *repo = NULL;
+ int *pack_fds = NULL;
uint32_t uuid_status;
*worktree = NULL;
@@ -190,12 +191,11 @@ open_worktree(struct got_worktree **worktree, const char *path)
goto done;
}
- err = got_repo_pack_fds_open(&(*worktree)->pack_fds);
+ err = got_repo_pack_fds_open(&pack_fds);
if (err)
goto done;
- err = got_repo_open(&repo, (*worktree)->repo_path, NULL,
- (*worktree)->pack_fds);
+ err = got_repo_open(&repo, (*worktree)->repo_path, NULL, pack_fds);
if (err)
goto done;
@@ -231,6 +231,12 @@ done:
if (err == NULL)
err = close_err;
}
+ if (pack_fds) {
+ const struct got_error *pack_err =
+ got_repo_pack_fds_close(pack_fds);
+ if (err == NULL)
+ err = pack_err;
+ }
free(path_got);
free(path_lock);
free(base_commit_id_str);
@@ -301,12 +307,6 @@ got_worktree_close(struct got_worktree *worktree)
if (close(worktree->root_fd) == -1 && err == NULL)
err = got_error_from_errno2("close",
got_worktree_get_root_path(worktree));
- if (worktree->pack_fds) {
- const struct got_error *pack_err =
- got_repo_pack_fds_close(worktree->pack_fds);
- if (err == NULL)
- err = pack_err;
- }
free(worktree->repo_path);
free(worktree->path_prefix);
free(worktree->base_commit_id);