summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-07-18 12:14:10 (GMT)
committerGitHub <noreply@github.com>2023-07-18 12:14:10 (GMT)
commita423ddbdeada8a2fd8657453b9e9f58ba0dd921d (patch)
tree92bf9ec6a80c41499f73a2d2e599df685ab8c4de /Python
parentb79f3b36c318be8b27d1737a819e33145193801c (diff)
downloadcpython-a423ddbdeada8a2fd8657453b9e9f58ba0dd921d.zip
cpython-a423ddbdeada8a2fd8657453b9e9f58ba0dd921d.tar.gz
cpython-a423ddbdeada8a2fd8657453b9e9f58ba0dd921d.tar.bz2
[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)
Diffstat (limited to 'Python')
-rw-r--r--Python/modsupport.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c
index be229c9..df4ae35 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -649,13 +649,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)
@@ -670,25 +673,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