Skip to content

Commit 146167b

Browse files
committed
Fix refleak on error
1 parent 48e172d commit 146167b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Modules/_testcapimodule.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,10 +3475,11 @@ static PyObject *
34753475
tracemalloc_track_race(PyObject *self, PyObject *args)
34763476
{
34773477
#define NTHREAD 50
3478+
PyObject *tracemalloc = NULL;
34783479
PyObject *stop = NULL;
34793480
tracemalloc_track_race_data data = {0};
34803481

3481-
PyObject *tracemalloc = PyImport_ImportModule("tracemalloc");
3482+
tracemalloc = PyImport_ImportModule("tracemalloc");
34823483
if (tracemalloc == NULL) {
34833484
goto error;
34843485
}
@@ -3494,7 +3495,7 @@ tracemalloc_track_race(PyObject *self, PyObject *args)
34943495
}
34953496

34963497
stop = PyObject_GetAttrString(tracemalloc, "stop");
3497-
Py_DECREF(tracemalloc);
3498+
Py_CLEAR(tracemalloc);
34983499
if (stop == NULL) {
34993500
goto error;
35003501
}
@@ -3536,6 +3537,7 @@ tracemalloc_track_race(PyObject *self, PyObject *args)
35363537
Py_RETURN_NONE;
35373538

35383539
error:
3540+
Py_CLEAR(tracemalloc);
35393541
Py_CLEAR(stop);
35403542
if (data.lock) {
35413543
PyThread_free_lock(data.lock);

0 commit comments

Comments
 (0)