https://github.com/python/cpython/commit/ff3f6588c3ecb6746a33f14030a90eb32467eece
commit: ff3f6588c3ecb6746a33f14030a90eb32467eece
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: vstinner <vstin...@python.org>
date: 2025-04-16T14:21:58Z
summary:

[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 014c7f90478780b18d0e33d456483178c8dcc665)

Co-authored-by: Victor Stinner <vstin...@python.org>

files:
M Modules/_testexternalinspection.c

diff --git a/Modules/_testexternalinspection.c 
b/Modules/_testexternalinspection.c
index 2a665affb5e7f8..2ed79f317b0417 100644
--- a/Modules/_testexternalinspection.c
+++ b/Modules/_testexternalinspection.c
@@ -345,8 +345,10 @@ get_py_runtime_linux(pid_t pid)
     }
 
 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);

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to