[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 3e65baee72).
(cherry picked from commit a423ddbdea)
This commit is contained in:
Serhiy Storchaka 2023-07-19 09:40:38 +03:00 committed by GitHub
parent 0c47ed7bbf
commit fced79f91e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 45 additions and 62 deletions

View file

@ -12563,7 +12563,7 @@ setup_confname_table(struct constdef *table, size_t tablesize,
}
Py_DECREF(o);
}
return PyModule_AddObject(module, tablename, d);
return _PyModule_Add(module, tablename, d);
}
/* Return -1 on failure, 0 on success. */
@ -15837,11 +15837,9 @@ posixmodule_exec(PyObject *m)
#endif
/* Initialize environ dictionary */
PyObject *v = convertenviron();
Py_XINCREF(v);
if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
if (_PyModule_Add(m, "environ", convertenviron()) != 0) {
return -1;
Py_DECREF(v);
}
if (all_ins(m))
return -1;
@ -15965,9 +15963,7 @@ posixmodule_exec(PyObject *m)
Py_DECREF(unicode);
}
PyModule_AddObject(m, "_have_functions", list);
return 0;
return _PyModule_Add(m, "_have_functions", list);
}