Skip to content
Merged
Prev Previous commit
Fix refleaks
  • Loading branch information
markshannon committed Feb 7, 2023
commit 99f0880e0d72075850c9abfe91e9a9fd3c8312df
6 changes: 4 additions & 2 deletions Modules/_testcapi/heaptype.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(
PyObject *exc = NULL;
PyObject *result = NULL;
PyObject *message = NULL;
PyObject *args = NULL;

metaclass_a = PyType_FromSpecWithBases(&MinimalMetaclass_spec, (PyObject*)&PyType_Type);
if (metaclass_a == NULL) {
Expand Down Expand Up @@ -156,13 +157,13 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(
// Assert that the correct exception was raised
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
exc = PyErr_GetRaisedException();
PyObject *args = PyException_GetArgs(exc);
args = PyException_GetArgs(exc);
if (!PyTuple_Check(args) || PyTuple_Size(args) != 1) {
PyErr_SetString(PyExc_AssertionError,
"TypeError args are not a one-tuple");
goto finally;
}
PyObject *message = Py_NewRef(PyTuple_GET_ITEM(args, 0));
message = Py_NewRef(PyTuple_GET_ITEM(args, 0));
meta_error_string = PyUnicode_FromString("metaclass conflict:");
if (meta_error_string == NULL) {
goto finally;
Expand All @@ -188,6 +189,7 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(
Py_XDECREF(message);
Py_XDECREF(class_a);
Py_XDECREF(class_b);
Py_XDECREF(args);
return result;
}

Expand Down
1 change: 1 addition & 0 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ _PyErr_Restore(PyThreadState *tstate, PyObject *type, PyObject *value,
}
else {
PyErr_SetString(PyExc_TypeError, "traceback must be a Traceback or None");
Py_XDECREF(value);
Py_DECREF(type);
Py_XDECREF(traceback);
return;
Expand Down