commit e9e7947043acbb1cb2962a4d2361c95af3dfe3b4 from: Omar Polo via: Thomas Adam date: Fri Apr 14 16:27:25 2023 UTC consistently close the struct repository on every cmd_*() Spotted while looking for leaks using Otto' malloc() new leaks detection. Harmless in practice since we just forgot to call got_repo_close() when terminating in some cmd_*() functions, but still a leak. ok stsp@ commit - 991857c7d6b96717f24bc49df50e8aacf12b02cf commit + e9e7947043acbb1cb2962a4d2361c95af3dfe3b4 blob - 293d3842bc39e809e4591897a7a0866c1a9f718f blob + f69b2fc972e4829dd036416d66095d49c43ab0cb --- got/got.c +++ got/got.c @@ -966,6 +966,11 @@ done: got_repo_pack_fds_close(pack_fds); if (error == NULL) error = pack_err; + } + if (repo) { + const struct got_error *close_err = got_repo_close(repo); + if (error == NULL) + error = close_err; } if (preserve_logmsg) { fprintf(stderr, "%s: log message preserved in %s\n", @@ -3213,6 +3218,11 @@ done: got_ref_close(head_ref); if (ref) got_ref_close(ref); + if (repo) { + const struct got_error *close_err = got_repo_close(repo); + if (error == NULL) + error = close_err; + } got_pathlist_free(&paths, GOT_PATHLIST_FREE_NONE); free(commit_id_str); free(commit_id); @@ -3453,7 +3463,11 @@ wrap_not_worktree_error(const struct got_error *orig_e "'got checkout'.\n" "The got(1) manual page contains more information.", cmdname); err = got_error_msg(GOT_ERR_NOT_WORKTREE, msg); - got_repo_close(repo); + if (repo) { + const struct got_error *close_err = got_repo_close(repo); + if (close_err == NULL) + err = close_err; + } if (pack_fds) { const struct got_error *pack_err = got_repo_pack_fds_close(pack_fds); @@ -3645,6 +3659,11 @@ done: got_repo_pack_fds_close(pack_fds); if (error == NULL) error = pack_err; + } + if (repo) { + const struct got_error *close_err = got_repo_close(repo); + if (error == NULL) + error = close_err; } free(worktree_path); got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH); @@ -6389,6 +6408,11 @@ done: if (error == NULL) error = pack_err; } + if (repo) { + const struct got_error *close_err = got_repo_close(repo); + if (error == NULL) + error = close_err; + } got_pathlist_free(&paths, GOT_PATHLIST_FREE_PATH); free(cwd);