Skip to content

Commit 3cd03e0

Browse files
committed
Fix refcounting
1 parent 1fc93c7 commit 3cd03e0

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

Objects/codeobject.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,38 +2457,37 @@ _PyCode_ConstantKey(PyObject *op)
24572457
}
24582458
else if (PySlice_Check(op)) {
24592459
PySliceObject *slice = (PySliceObject *)op;
2460+
PyObject *start_key = NULL;
2461+
PyObject *stop_key = NULL;
2462+
PyObject *step_key = NULL;
2463+
key = NULL;
24602464

2461-
PyObject *start = slice->start;
2462-
PyObject *start_key = _PyCode_ConstantKey(start);
2465+
start_key = _PyCode_ConstantKey(slice->start);
24632466
if (start_key == NULL) {
2464-
return NULL;
2467+
goto slice_exit;
24652468
}
24662469

2467-
PyObject *stop = slice->stop;
2468-
PyObject *stop_key = _PyCode_ConstantKey(stop);
2470+
stop_key = _PyCode_ConstantKey(slice->stop);
24692471
if (stop_key == NULL) {
2470-
Py_DECREF(start_key);
2471-
return NULL;
2472+
goto slice_exit;
24722473
}
24732474

2474-
PyObject *step = slice->step;
2475-
PyObject *step_key = _PyCode_ConstantKey(step);
2475+
step_key = _PyCode_ConstantKey(slice->step);
24762476
if (step_key == NULL) {
2477-
Py_DECREF(start_key);
2478-
Py_DECREF(stop_key);
2479-
return NULL;
2477+
goto slice_exit;
24802478
}
24812479

24822480
PyObject *slice_key = PySlice_New(start_key, stop_key, step_key);
24832481
if (slice_key == NULL) {
2484-
Py_DECREF(start_key);
2485-
Py_DECREF(stop_key);
2486-
Py_DECREF(step_key);
2487-
return NULL;
2482+
goto slice_exit;
24882483
}
24892484

24902485
key = PyTuple_Pack(2, slice_key, op);
24912486
Py_DECREF(slice_key);
2487+
slice_exit:
2488+
Py_XDECREF(start_key);
2489+
Py_XDECREF(stop_key);
2490+
Py_XDECREF(step_key);
24922491
}
24932492
else {
24942493
/* for other types, use the object identifier as a unique identifier

0 commit comments

Comments
 (0)