commit 72fd8fc46dbf82d2aef3596866e49047d68e761b from: Mark Jamsek date: Tue Jan 21 15:22:19 2025 UTC plug memleak and ensure fd is valid before passing to close(2) While here, fix potential NULL deref in gotadmin cleanup and pack error paths. ok stsp@ commit - d855ad4fcc82e94f9232218d35c19c5f88b5d243 commit + 72fd8fc46dbf82d2aef3596866e49047d68e761b blob - 3659093bee84b25db368dbe3c0e93a76adf6ed2d blob + 62a5c6397e3238e2deac79abfc06c76a3d586dcd --- lib/repository_admin.c +++ lib/repository_admin.c @@ -162,8 +162,10 @@ create_temp_packfile(int *packfd, char **tmpfile_path, if (fchmod(*packfd, GOT_DEFAULT_PACK_MODE) == -1) err = got_error_from_errno2("fchmod", *tmpfile_path); done: + free(path); if (err) { - close(*packfd); + if (*packfd != -1) + close(*packfd); *packfd = -1; free(*tmpfile_path); *tmpfile_path = NULL; @@ -287,7 +289,8 @@ done: free(theirs[i]); free(theirs); if (packfd != -1 && close(packfd) == -1 && err == NULL) - err = got_error_from_errno2("close", packfile_path); + err = got_error_from_errno2("close", + packfile_path ? packfile_path : tmpfile_path); if (delta_cache && fclose(delta_cache) == EOF && err == NULL) err = got_error_from_errno("fclose"); if (tmpfile_path && unlink(tmpfile_path) == -1 && err == NULL) @@ -1593,7 +1596,8 @@ got_repo_cleanup(struct got_repository *repo, if (traversed_ids) got_object_idset_free(traversed_ids); if (packfd != -1 && close(packfd) == -1 && err == NULL) - err = got_error_from_errno2("close", packfile_path); + err = got_error_from_errno2("close", + packfile_path ? packfile_path : tmpfile_path); if (delta_cache && fclose(delta_cache) == EOF && err == NULL) err = got_error_from_errno("fclose"); if (tmpfile_path && unlink(tmpfile_path) == -1 && err == NULL)