[Python-checkins] bpo-42425: Fix possible leak in initialization of errmap for OSError (GH-23446)

serhiy-storchaka webhook-mailer at python.org
Sat Nov 21 12:17:53 EST 2020


https://github.com/python/cpython/commit/ed1007c0d74e658d1e6c9b51b12ce7501eb8cbf9
commit: ed1007c0d74e658d1e6c9b51b12ce7501eb8cbf9
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2020-11-21T19:17:46+02:00
summary:

bpo-42425: Fix possible leak in initialization of errmap for OSError (GH-23446)

files:
M Objects/exceptions.c

diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index b14da20db0c4e..d4824938a0f50 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -2547,8 +2547,10 @@ _PyExc_Init(PyThreadState *tstate)
     do { \
         PyObject *_code = PyLong_FromLong(CODE); \
         assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \
-        if (!_code || PyDict_SetItem(state->errnomap, _code, PyExc_ ## TYPE)) \
+        if (!_code || PyDict_SetItem(state->errnomap, _code, PyExc_ ## TYPE)) { \
+            Py_XDECREF(_code); \
             return _PyStatus_ERR("errmap insertion problem."); \
+        } \
         Py_DECREF(_code); \
     } while (0)
 



More information about the Python-checkins mailing list