Skip to content

Commit 8a9463f

Browse files
authored
_testmultiphase: Fix possible ref leak (GH-22881)
This is just test code, but sometimes external contributors reference the code snippets from test code. `PyModule_AddObject` should be handled in the proper way. https://docs.python.org/3/c-api/module.html#c.PyModule_AddObject
1 parent c8ba47b commit 8a9463f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Modules/_testmultiphase.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ static int execfunc(PyObject *m)
359359
goto fail;
360360
}
361361
if (PyModule_AddObject(m, "Example", temp) != 0) {
362+
Py_DECREF(temp);
362363
goto fail;
363364
}
364365

@@ -369,6 +370,7 @@ static int execfunc(PyObject *m)
369370
goto fail;
370371
}
371372
if (PyModule_AddObject(m, "error", temp) != 0) {
373+
Py_DECREF(temp);
372374
goto fail;
373375
}
374376

@@ -378,6 +380,7 @@ static int execfunc(PyObject *m)
378380
goto fail;
379381
}
380382
if (PyModule_AddObject(m, "Str", temp) != 0) {
383+
Py_DECREF(temp);
381384
goto fail;
382385
}
383386

@@ -807,6 +810,7 @@ meth_state_access_exec(PyObject *m)
807810
return -1;
808811
}
809812
if (PyModule_AddObject(m, "StateAccessType", temp) != 0) {
813+
Py_DECREF(temp);
810814
return -1;
811815
}
812816

0 commit comments

Comments
 (0)