[3.13] gh-130052: Fix search_map_for_section() error handling (GH-132594) (#132598)

gh-130052: Fix search_map_for_section() error handling (GH-132594)

* Don't call close() if the file descriptor is negative.
* If close() fails, chain the existing exception.
(cherry picked from commit 014c7f9047)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2025-04-16 16:21:58 +02:00 committed by GitHub
parent ee8f681252
commit ff3f6588c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -345,8 +345,10 @@ get_py_runtime_linux(pid_t pid)
} }
exit: exit:
if (close(fd) != 0) { if (fd >= 0 && close(fd) != 0) {
PyObject *exc = PyErr_GetRaisedException();
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
_PyErr_ChainExceptions1(exc);
} }
if (file_memory != NULL) { if (file_memory != NULL) {
munmap(file_memory, file_stats.st_size); munmap(file_memory, file_stats.st_size);