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

* Don't call close() if the file descriptor is negative.
* If close() fails, chain the existing exception.
This commit is contained in:
Victor Stinner 2025-04-16 15:56:58 +02:00 committed by GitHub
parent 7dcaebfb21
commit 014c7f9047
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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