diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-07-19 06:40:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-19 06:40:38 (GMT) |
commit | fced79f91e186dd6a608221ad7cee2eeb443c40d (patch) | |
tree | 1fb2424e9896c609fde2f1b3675ba106c9c55466 /Python | |
parent | 0c47ed7bbf156e9fc01e276ef053206f3e6a3e62 (diff) | |
download | cpython-fced79f91e186dd6a608221ad7cee2eeb443c40d.zip cpython-fced79f91e186dd6a608221ad7cee2eeb443c40d.tar.gz cpython-fced79f91e186dd6a608221ad7cee2eeb443c40d.tar.bz2 |
[3.11] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855) (GH-106863)
[3.11] [3.12] gh-86493: Fix possible leaks in some modules initialization (GH-106768) (GH-106855)
Fix _ssl, _stat, _testinternalcapi, _threadmodule, cmath, math, posix, time.
(cherry picked from commit 3e65baee72131b49f4ce8ca2da568a6f2001ce93).
(cherry picked from commit a423ddbdeada8a2fd8657453b9e9f58ba0dd921d)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/modsupport.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c index 8655daa..89ffae8 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -658,13 +658,16 @@ PyModule_AddObjectRef(PyObject *mod, const char *name, PyObject *value) PyModule_GetName(mod)); return -1; } - - if (PyDict_SetItemString(dict, name, value)) { - return -1; - } - return 0; + return PyDict_SetItemString(dict, name, value); } +int +_PyModule_Add(PyObject *mod, const char *name, PyObject *value) +{ + int res = PyModule_AddObjectRef(mod, name, value); + Py_XDECREF(value); + return res; +} int PyModule_AddObject(PyObject *mod, const char *name, PyObject *value) @@ -679,25 +682,13 @@ PyModule_AddObject(PyObject *mod, const char *name, PyObject *value) int PyModule_AddIntConstant(PyObject *m, const char *name, long value) { - PyObject *obj = PyLong_FromLong(value); - if (!obj) { - return -1; - } - int res = PyModule_AddObjectRef(m, name, obj); - Py_DECREF(obj); - return res; + return _PyModule_Add(m, name, PyLong_FromLong(value)); } int PyModule_AddStringConstant(PyObject *m, const char *name, const char *value) { - PyObject *obj = PyUnicode_FromString(value); - if (!obj) { - return -1; - } - int res = PyModule_AddObjectRef(m, name, obj); - Py_DECREF(obj); - return res; + return _PyModule_Add(m, name, PyUnicode_FromString(value)); } int |