commit 575ccdcfa027a0819df9f362eaf787142709ce2e from: Mark Jamsek via: Thomas Adam date: Sun Dec 03 21:51:13 2023 UTC plug got checkout and update worktree leaks spotted by op@ commit - b2424a42ae549628fe7e8ac9bf5b69af89f59d46 commit + 575ccdcfa027a0819df9f362eaf787142709ce2e blob - 43915712200e8129be6dcf3d80b1b9a9ba2b6199 blob + 6cca04c7b61becb9df4fb50674ec1414ee0cdbe0 --- got/got.c +++ got/got.c @@ -2994,7 +2994,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; @@ -3250,7 +3250,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; } @@ -3511,7 +3516,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; @@ -3706,10 +3711,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);