10000 Fix refleaks · python/cpython@99f0880 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99f0880

Browse files
committed
Fix refleaks
1 parent 566f6e1 commit 99f0880

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Modules/_testcapi/heaptype.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(
119119
PyObject *exc = NULL;
120120
PyObject *result = NULL;
121121
PyObject *message = NULL;
122+
PyObject *args = NULL;
122123

123124
metaclass_a = PyType_FromSpecWithBases(&MinimalMetaclass_spec, (PyObject*)&PyType_Type);
124125
if (metaclass_a == NULL) {
@@ -156,13 +157,13 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(
156157
// Assert that the correct exception was raised
157158
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
158159
exc = PyErr_GetRaisedException();
159-
PyObject *args = PyException_GetArgs(exc);
160+
args = PyException_GetArgs(exc);
160161
if (!PyTuple_Check(args) || PyTuple_Size(args) != 1) {
161162
PyErr_SetString(PyExc_AssertionError,
162163
"TypeError args are not a one-tuple");
163164
goto finally;
164165
}
165-
PyObject *message = Py_NewRef(PyTuple_GET_ITEM(args, 0));
166+
message = Py_NewRef(PyTuple_GET_ITEM(args, 0));
166167
meta_error_string = PyUnicode_FromString("metaclass conflict:");
167168
if (meta_error_string == NULL) {
168169
goto finally;
@@ -188,6 +189,7 @@ test_from_spec_invalid_metatype_inheritance(PyObject *self, PyObject *Py_UNUSED(
188189
Py_XDECREF(message);
189190
Py_XDECREF(class_a);
190191
Py_XDECREF(class_b);
192+
Py_XDECREF(args);
191193
return result;
192194
}
193195

Python/errors.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ _PyErr_Restore(PyThreadState *tstate, PyObject *type, PyObject *value,
9494
}
9595
else {
9696
PyErr_SetString(PyExc_TypeError, "traceback must be a Traceback or None");
97+
Py_XDECREF(value);
9798
Py_DECREF(type);
9899
Py_XDECREF(traceback);
99100
return;

0 commit comments

Comments
 (0)
0