Skip to content

Commit 014c7f9

Browse files
authored
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.
1 parent 7dcaebf commit 014c7f9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Modules/_testexternalinspection.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,10 @@ search_map_for_section(pid_t pid, const char* secname, const char* map)
400400
}
401401

402402
exit:
403-
if (close(fd) != 0) {
403+
if (fd >= 0 && close(fd) != 0) {
404+
PyObject *exc = PyErr_GetRaisedException();
404405
PyErr_SetFromErrno(PyExc_OSError);
406+
_PyErr_ChainExceptions1(exc);
405407
}
406408
if (file_memory != NULL) {
407409
munmap(file_memory, file_stats.st_size);

0 commit comments

Comments
 (0)