]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130052: Fix search_map_for_section() error handling (#132594)
authorVictor Stinner <vstinner@python.org>
Wed, 16 Apr 2025 13:56:58 +0000 (15:56 +0200)
committerGitHub <noreply@github.com>
Wed, 16 Apr 2025 13:56:58 +0000 (13:56 +0000)
* Don't call close() if the file descriptor is negative.
* If close() fails, chain the existing exception.

Modules/_testexternalinspection.c

index e90cfb9132b51d079aabd74eaea36f5f7b32e948..01fe700fa490f136163f90d0bbb5427c78832165 100644 (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);