commit 223f4ba8a53034e099a1596ecc1d8430ea61e8a4 from: Mark Jamsek via: Thomas Adam date: Fri Jan 24 22:02:34 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 - 44e1226a2053c76971c5bb2b222acf720453f866 commit + 223f4ba8a53034e099a1596ecc1d8430ea61e8a4 blob - aed0ab8b6184bc0a8594af6b2dd77d8d856d88df blob + 1197d7902e8a188ee3b31346586a09ae40a16f43 --- lib/repository_admin.c +++ lib/repository_admin.c @@ -159,8 +159,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; @@ -284,7 +286,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) @@ -1590,7 +1593,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)