Skip to content

Commit

Permalink
Fix double decref in error path
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jun 30, 2024
1 parent 5df23bf commit 6b63066
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
32 changes: 3 additions & 29 deletions Lib/idlelib/idle_test/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,38 +396,12 @@ def test_fatal_error(self):
self.assertIn('IndexError', msg)
eq(func.called, 2)


a = []
x = a.append
class ExecRuncodeTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.addClassCleanup(setattr,run,'print_exception',run.print_exception)
cls.prt = Func() # Need reference.
run.print_exception = cls.prt
mockrpc = mock.Mock()
mockrpc.console.getvar = Func(result=False)
cls.ex = run.Executive(mockrpc)

@classmethod
def tearDownClass(cls):
assert sys.excepthook == sys.__excepthook__

def test_exceptions(self):
ex = self.ex
ex.runcode('1/0')
self.assertIs(ex.user_exc_info[0], ZeroDivisionError)

self.addCleanup(setattr, sys, 'excepthook', sys.__excepthook__)
sys.excepthook = lambda t, e, tb: run.print_exception(t)
ex.runcode('1/0')
self.assertIs(self.prt.args[0], ZeroDivisionError)

sys.excepthook = lambda: None
ex.runcode('1/0')
t, e, tb = ex.user_exc_info
self.assertIs(t, TypeError)
self.assertTrue(isinstance(e.__context__, ZeroDivisionError))

x(lambda a:a)

if __name__ == '__main__':
unittest.main(verbosity=2)
4 changes: 3 additions & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3385,7 +3385,9 @@ dummy_func(
/* Callable is not a normal Python function */
STACKREFS_TO_PYOBJECTS_BORROW(args, total_args, args_o);
if (CONVERSION_FAILED(args_o)) {
DECREF_INPUTS();
for (int i = 0; i < total_args; i++) {
PyStackRef_CLOSE(args[i]);
}
ERROR_IF(true, error);
}
PyObject *res_o = PyObject_Vectorcall(
Expand Down
2 changes: 1 addition & 1 deletion Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b63066

Please sign in to comment.