summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cprofile.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-09-29 03:41:21 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-09-29 03:41:21 (GMT)
commitb2d61bde28d11ab5f31ee7cd2738828f801c68d9 (patch)
treedc5d0420f6d5d8b7b3a01bb3787c01836652b23b /Lib/test/test_cprofile.py
parent09c01782424e61e51dbfab83886738aacd73a635 (diff)
downloadcpython-b2d61bde28d11ab5f31ee7cd2738828f801c68d9.zip
cpython-b2d61bde28d11ab5f31ee7cd2738828f801c68d9.tar.gz
cpython-b2d61bde28d11ab5f31ee7cd2738828f801c68d9.tar.bz2
The _lsprof module could crash the interpreter if it was given an external
timer that did not return a float and a timer was still running when the Profiler object was garbage collected. Fixes issue 3895. Code review by Benjamin Peterson.
Diffstat (limited to 'Lib/test/test_cprofile.py')
-rwxr-xr-xLib/test/test_cprofile.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py
index 7ed6cec..13c1060 100755
--- a/Lib/test/test_cprofile.py
+++ b/Lib/test/test_cprofile.py
@@ -1,7 +1,7 @@
"""Test suite for the cProfile module."""
import sys
-from test.test_support import run_unittest
+from test.test_support import run_unittest, TESTFN, unlink
# rip off all interesting stuff from test_profile
import cProfile
@@ -10,6 +10,20 @@ from test.test_profile import ProfileTest, regenerate_expected_output
class CProfileTest(ProfileTest):
profilerclass = cProfile.Profile
+ # Issue 3895.
+ def test_bad_counter_during_dealloc(self):
+ import _lsprof
+ # Must use a file as StringIO doesn't trigger the bug.
+ sys.stderr = open(TESTFN, 'w')
+ try:
+ obj = _lsprof.Profiler(lambda: int)
+ obj.enable()
+ obj = _lsprof.Profiler(1)
+ obj.disable()
+ finally:
+ sys.stderr = sys.__stderr__
+ unlink(TESTFN)
+
def test_main():
run_unittest(CProfileTest)