Skip to content

Commit df44ab7

Browse files
committed
_hotshot hotshot_profiler(): If write_header() returned
an error code, this let `self` leak. This is a disaster on Windows, since `self` already points to a newly-opened file object, and it was impossible for Python code to close the thing since the only reference to it was in a blob of leaked C memory. test_hotshot test_bad_sys_path(): This new test provoked the C bug above. This test passed, but left an open "@test" file behind, which caused a massive cascade of bogus test failures in later, unrelated tests on Windows. Changed the test code to remove the @test file it leaves behind, which relies on the change above to close that file first.
1 parent 516999e commit df44ab7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Lib/test/test_hotshot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,20 @@ def test_start_stop(self):
109109

110110
def test_bad_sys_path(self):
111111
import sys
112+
import os
112113
orig_path = sys.path
113114
coverage = hotshot._hotshot.coverage
114115
try:
115116
# verify we require a list for sys.path
116117
sys.path = 'abc'
117118
self.assertRaises(RuntimeError, coverage, test_support.TESTFN)
118-
# verify sys.path exists
119+
# verify that we require sys.path exists
119120
del sys.path
120121
self.assertRaises(RuntimeError, coverage, test_support.TESTFN)
121122
finally:
122123
sys.path = orig_path
124+
if os.path.exists(test_support.TESTFN):
125+
os.remove(test_support.TESTFN)
123126

124127
def test_main():
125128
test_support.run_unittest(HotShotTestCase)

Modules/_hotshot.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,11 @@ hotshot_profiler(PyObject *unused, PyObject *args)
15251525
calibrate();
15261526
calibrate();
15271527
}
1528-
if (write_header(self))
1528+
if (write_header(self)) {
15291529
/* some error occurred, exception has been set */
1530+
Py_DECREF(self);
15301531
self = NULL;
1532+
}
15311533
}
15321534
return (PyObject *) self;
15331535
}

0 commit comments

Comments
 (0)