Skip to content

Commit c7c13da

Browse files
committed
Fix leaks
1 parent 588b3e5 commit c7c13da

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Modules/_testcapi/set.c

+11-5
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,26 @@ test_frozenset_add_in_capi(PyObject *self, PyObject *Py_UNUSED(obj))
140140
}
141141
PyObject *num = PyLong_FromLong(1);
142142
if (num == NULL) {
143-
return NULL;
143+
goto error;
144144
}
145145
if (PySet_Add(fs, num) < 0) {
146-
return NULL;
146+
goto error;
147147
}
148148
int contains = PySet_Contains(fs, num);
149149
if (contains < 0) {
150-
return NULL;
150+
goto error;
151151
}
152152
else if (contains == 0) {
153-
PyErr_SetString(PyExc_ValueError, "set does not contain expected value");
154-
return NULL;
153+
goto unexpected;
155154
}
156155
Py_RETURN_NONE;
156+
157+
unexpected:
158+
PyErr_SetString(PyExc_ValueError, "set does not contain expected value");
159+
error:
160+
Py_DECREF(fs);
161+
Py_XDECREF(num);
162+
return NULL;
157163
}
158164

159165
static PyMethodDef test_methods[] = {

0 commit comments

Comments
 (0)