Skip to content

Commit 1a95ad6

Browse files
JelleZijlstraaisk
andauthored
[3.12] gh-111654: remove redundant decref in LOAD_FROM_DICT_OR_DEREF (GH-111655) (#111674)
(cherry picked from commit 3a1b09e) Co-authored-by: AN Long <[email protected]>
1 parent 4db71c3 commit 1a95ad6

File tree

4 files changed

+286
-281
lines changed

4 files changed

+286
-281
lines changed

Lib/test/test_exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,13 @@ def f():
18241824
self.assertIn("nonsense", err.getvalue())
18251825
self.assertIn("ZeroDivisionError", err.getvalue())
18261826

1827+
def test_gh_111654(self):
1828+
def f():
1829+
class TestClass:
1830+
TestClass
1831+
1832+
self.assertRaises(NameError, f)
1833+
18271834
# Note: name suggestion tests live in `test_traceback`.
18281835

18291836

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix runtime crash when some error happens in opcode
2+
``LOAD_FROM_DICT_OR_DEREF``.

Python/bytecodes.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,21 +1425,18 @@ dummy_func(
14251425
Py_INCREF(value);
14261426
}
14271427
else if (_PyErr_Occurred(tstate)) {
1428-
Py_DECREF(class_dict);
14291428
goto error;
14301429
}
14311430
}
14321431
else {
14331432
value = PyObject_GetItem(class_dict, name);
14341433
if (value == NULL) {
14351434
if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
1436-
Py_DECREF(class_dict);
14371435
goto error;
14381436
}
14391437
_PyErr_Clear(tstate);
14401438
}
14411439
}
1442-
Py_DECREF(class_dict);
14431440
if (!value) {
14441441
PyObject *cell = GETLOCAL(oparg);
14451442
value = PyCell_GET(cell);
@@ -1449,6 +1446,7 @@ dummy_func(
14491446
}
14501447
Py_INCREF(value);
14511448
}
1449+
Py_DECREF(class_dict);
14521450
}
14531451

14541452
inst(LOAD_DEREF, ( -- value)) {

0 commit comments

Comments
 (0)