Kaydet (Commit) 31949b91 authored tarafından Amaury Forgeot d'Arc's avatar Amaury Forgeot d'Arc

#3954: Fix error handling code in _hotshot.logreader

Will port to 2.6. hotshot was deleted from python 3.
üst 68060013
...@@ -3,6 +3,8 @@ import hotshot.log ...@@ -3,6 +3,8 @@ import hotshot.log
import os import os
import pprint import pprint
import unittest import unittest
import _hotshot
import gc
from test import test_support from test import test_support
...@@ -124,6 +126,10 @@ class HotShotTestCase(unittest.TestCase): ...@@ -124,6 +126,10 @@ class HotShotTestCase(unittest.TestCase):
if os.path.exists(test_support.TESTFN): if os.path.exists(test_support.TESTFN):
os.remove(test_support.TESTFN) os.remove(test_support.TESTFN)
def test_logreader_eof_error(self):
self.assertRaises((IOError, EOFError), _hotshot.logreader, ".")
gc.collect()
def test_main(): def test_main():
test_support.run_unittest(HotShotTestCase) test_support.run_unittest(HotShotTestCase)
......
...@@ -74,6 +74,9 @@ Core and Builtins ...@@ -74,6 +74,9 @@ Core and Builtins
Library Library
------- -------
- Issue #3954: Fix a potential SystemError in _hotshot.logreader error
handling.
- Issue #4574: fix a crash in io.IncrementalNewlineDecoder when a carriage - Issue #4574: fix a crash in io.IncrementalNewlineDecoder when a carriage
return encodes to more than one byte in the source encoding (e.g. UTF-16) return encodes to more than one byte in the source encoding (e.g. UTF-16)
and gets split on a chunk boundary. and gets split on a chunk boundary.
......
...@@ -1357,20 +1357,16 @@ hotshot_logreader(PyObject *unused, PyObject *args) ...@@ -1357,20 +1357,16 @@ hotshot_logreader(PyObject *unused, PyObject *args)
self->logfp = fopen(filename, "rb"); self->logfp = fopen(filename, "rb");
if (self->logfp == NULL) { if (self->logfp == NULL) {
PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename); PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
Py_DECREF(self); goto error;
self = NULL;
goto finally;
} }
self->info = PyDict_New(); self->info = PyDict_New();
if (self->info == NULL) { if (self->info == NULL)
Py_DECREF(self); goto error;
goto finally;
}
/* read initial info */ /* read initial info */
for (;;) { for (;;) {
if ((c = fgetc(self->logfp)) == EOF) { if ((c = fgetc(self->logfp)) == EOF) {
eof_error(self); eof_error(self);
break; goto error;
} }
if (c != WHAT_ADD_INFO) { if (c != WHAT_ADD_INFO) {
ungetc(c, self->logfp); ungetc(c, self->logfp);
...@@ -1383,13 +1379,15 @@ hotshot_logreader(PyObject *unused, PyObject *args) ...@@ -1383,13 +1379,15 @@ hotshot_logreader(PyObject *unused, PyObject *args)
else else
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
"unexpected error"); "unexpected error");
break; goto error;
} }
} }
} }
} }
finally:
return (PyObject *) self; return (PyObject *) self;
error:
Py_DECREF(self);
return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment