Skip to content

Commit 0826920

Browse files
pythongh-86493: Fix possible leaks in modules initialization: _curses_panel, _decimal, xxsubtype
1 parent 32718f9 commit 0826920

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

Modules/_curses_panel.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,7 @@ _curses_panel_exec(PyObject *mod)
662662
state->PyCursesError = PyErr_NewException(
663663
"_curses_panel.error", NULL, NULL);
664664

665-
if (PyModule_AddObject(mod, "error", Py_NewRef(state->PyCursesError)) < 0) {
666-
Py_DECREF(state->PyCursesError);
665+
if (PyModule_AddObjectRef(mod, "error", state->PyCursesError) < 0) {
667666
return -1;
668667
}
669668

Modules/_decimal/_decimal.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5957,7 +5957,7 @@ PyInit__decimal(void)
59575957
Py_DECREF(base);
59585958

59595959
/* add to module */
5960-
CHECK_INT(PyModule_AddObject(m, cm->name, Py_NewRef(cm->ex)));
5960+
CHECK_INT(PyModule_AddObjectRef(m, cm->name, cm->ex));
59615961

59625962
/* add to signal tuple */
59635963
PyTuple_SET_ITEM(state->SignalTuple, i, Py_NewRef(cm->ex));
@@ -5986,39 +5986,39 @@ PyInit__decimal(void)
59865986
ASSIGN_PTR(cm->ex, PyErr_NewException(cm->fqname, base, NULL));
59875987
Py_DECREF(base);
59885988

5989-
CHECK_INT(PyModule_AddObject(m, cm->name, Py_NewRef(cm->ex)));
5989+
CHECK_INT(PyModule_AddObjectRef(m, cm->name, cm->ex));
59905990
}
59915991

59925992

59935993
/* Init default context template first */
59945994
ASSIGN_PTR(state->default_context_template,
59955995
PyObject_CallObject((PyObject *)state->PyDecContext_Type, NULL));
5996-
CHECK_INT(PyModule_AddObject(m, "DefaultContext",
5997-
Py_NewRef(state->default_context_template)));
5996+
CHECK_INT(PyModule_AddObjectRef(m, "DefaultContext",
5997+
state->default_context_template));
59985998

59995999
#ifndef WITH_DECIMAL_CONTEXTVAR
60006000
ASSIGN_PTR(state->tls_context_key,
60016001
PyUnicode_FromString("___DECIMAL_CTX__"));
6002-
CHECK_INT(PyModule_AddObject(m, "HAVE_CONTEXTVAR", Py_NewRef(Py_False)));
6002+
CHECK_INT(PyModule_AddObjectRef(m, "HAVE_CONTEXTVAR", Py_False));
60036003
#else
60046004
ASSIGN_PTR(state->current_context_var, PyContextVar_New("decimal_context", NULL));
6005-
CHECK_INT(PyModule_AddObject(m, "HAVE_CONTEXTVAR", Py_NewRef(Py_True)));
6005+
CHECK_INT(PyModule_AddObjectRef(m, "HAVE_CONTEXTVAR", Py_True));
60066006
#endif
6007-
CHECK_INT(PyModule_AddObject(m, "HAVE_THREADS", Py_NewRef(Py_True)));
6007+
CHECK_INT(PyModule_AddObjectRef(m, "HAVE_THREADS", Py_True));
60086008

60096009
/* Init basic context template */
60106010
ASSIGN_PTR(state->basic_context_template,
60116011
PyObject_CallObject((PyObject *)state->PyDecContext_Type, NULL));
60126012
init_basic_context(state->basic_context_template);
6013-
CHECK_INT(PyModule_AddObject(m, "BasicContext",
6014-
Py_NewRef(state->basic_context_template)));
6013+
CHECK_INT(PyModule_AddObjectRef(m, "BasicContext",
6014+
state->basic_context_template));
60156015

60166016
/* Init extended context template */
60176017
ASSIGN_PTR(state->extended_context_template,
60186018
PyObject_CallObject((PyObject *)state->PyDecContext_Type, NULL));
60196019
init_extended_context(state->extended_context_template);
6020-
CHECK_INT(PyModule_AddObject(m, "ExtendedContext",
6021-
Py_NewRef(state->extended_context_template)));
6020+
CHECK_INT(PyModule_AddObjectRef(m, "ExtendedContext",
6021+
state->extended_context_template));
60226022

60236023

60246024
/* Init mpd_ssize_t constants */
@@ -6037,7 +6037,7 @@ PyInit__decimal(void)
60376037
/* Init string constants */
60386038
for (i = 0; i < _PY_DEC_ROUND_GUARD; i++) {
60396039
ASSIGN_PTR(state->round_map[i], PyUnicode_InternFromString(mpd_round_string[i]));
6040-
CHECK_INT(PyModule_AddObject(m, mpd_round_string[i], Py_NewRef(state->round_map[i])));
6040+
CHECK_INT(PyModule_AddObjectRef(m, mpd_round_string[i], state->round_map[i]));
60416041
}
60426042

60436043
/* Add specification version number */

Modules/xxsubtype.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,10 @@ xxsubtype_exec(PyObject* m)
274274
if (PyType_Ready(&spamdict_type) < 0)
275275
return -1;
276276

277-
if (PyModule_AddObject(m, "spamlist",
278-
Py_NewRef(&spamlist_type)) < 0)
277+
if (PyModule_AddObjectRef(m, "spamlist", (PyObject *)&spamlist_type) < 0)
279278
return -1;
280279

281-
if (PyModule_AddObject(m, "spamdict",
282-
Py_NewRef(&spamdict_type)) < 0)
280+
if (PyModule_AddObjectRef(m, "spamdict", (PyObject *)&spamdict_type) < 0)
283281
return -1;
284282
return 0;
285283
}

0 commit comments

Comments
 (0)