Skip to content

Commit 1773d78

Browse files
committed
Simplofy cleanup
1 parent db35f6e commit 1773d78

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

Modules/_remote_debugging_module.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -826,54 +826,62 @@ parse_task(
826826
int recurse_task
827827
) {
828828
char is_task;
829-
int err = read_char(
829+
PyObject* result = NULL;
830+
PyObject* awaited_by = NULL;
831+
int err;
832+
833+
err = read_char(
830834
&unwinder->handle,
831835
task_address + unwinder->async_debug_offsets.asyncio_task_object.task_is_task,
832836
&is_task);
833837
if (err) {
834-
return -1;
838+
goto error;
835839
}
836840

837-
PyObject* result = NULL;
838841
if (is_task) {
839842
result = create_task_result(unwinder, task_address, recurse_task);
840843
if (!result) {
841-
return -1;
844+
goto error;
842845
}
843846
} else {
844847
result = PyList_New(0);
845848
if (result == NULL) {
846-
return -1;
849+
goto error;
847850
}
848851
}
849852

850853
if (PyList_Append(render_to, result)) {
851-
Py_DECREF(result);
852-
return -1;
854+
goto error;
853855
}
854856

855857
if (recurse_task) {
856-
PyObject *awaited_by = PyList_New(0);
858+
awaited_by = PyList_New(0);
857859
if (awaited_by == NULL) {
858-
Py_DECREF(result);
859-
return -1;
860+
goto error;
860861
}
862+
861863
if (PyList_Append(result, awaited_by)) {
862-
Py_DECREF(awaited_by);
863-
Py_DECREF(result);
864-
return -1;
864+
goto error;
865865
}
866-
/* we can operate on a borrowed one to simplify cleanup */
867866
Py_DECREF(awaited_by);
868867

868+
/* awaited_by is borrowed from 'result' to simplify cleanup */
869869
if (parse_task_awaited_by(unwinder, task_address, awaited_by, 1) < 0) {
870-
Py_DECREF(result);
871-
return -1;
870+
// Clear the pointer so the cleanup doesn't try to decref it since
871+
// it's borrowed from 'result' and will be decrefed when result is
872+
// deleted.
873+
awaited_by = NULL;
874+
goto error;
872875
}
873876
}
874877
Py_DECREF(result);
875878

876879
return 0;
880+
881+
error:
882+
Py_XDECREF(result);
883+
Py_XDECREF(awaited_by);
884+
return -1;
877885
}
878886

879887
static int

0 commit comments

Comments
 (0)