[Python-checkins] r67797 - in python/trunk: Lib/test/test_hotshot.py Misc/NEWS Modules/_hotshot.c

amaury.forgeotdarc python-checkins at python.org
Mon Dec 15 22:47:57 CET 2008


Author: amaury.forgeotdarc
Date: Mon Dec 15 22:47:57 2008
New Revision: 67797
Log:
#3954: Fix error handling code in _hotshot.logreader
Will port to 2.6 and 3.0.
Modified:
 python/trunk/Lib/test/test_hotshot.py
 python/trunk/Misc/NEWS
 python/trunk/Modules/_hotshot.c
Modified: python/trunk/Lib/test/test_hotshot.py
==============================================================================
--- python/trunk/Lib/test/test_hotshot.py	(original)
+++ python/trunk/Lib/test/test_hotshot.py	Mon Dec 15 22:47:57 2008
@@ -3,6 +3,8 @@
 import os
 import pprint
 import unittest
+import _hotshot
+import gc
 
 from test import test_support
 
@@ -124,6 +126,10 @@
 if os.path.exists(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():
 test_support.run_unittest(HotShotTestCase)
 
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon Dec 15 22:47:57 2008
@@ -74,6 +74,9 @@
 Library
 -------
 
+- Issue #3954: Fix a potential SystemError in _hotshot.logreader error
+ handling.
+
 - 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)
 and gets split on a chunk boundary.
Modified: python/trunk/Modules/_hotshot.c
==============================================================================
--- python/trunk/Modules/_hotshot.c	(original)
+++ python/trunk/Modules/_hotshot.c	Mon Dec 15 22:47:57 2008
@@ -1357,20 +1357,16 @@
 self->logfp = fopen(filename, "rb");
 if (self->logfp == NULL) {
 PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
- Py_DECREF(self);
- self = NULL;
- goto finally;
+ goto error;
 }
 self->info = PyDict_New();
- if (self->info == NULL) {
- Py_DECREF(self);
- goto finally;
- }
+ if (self->info == NULL)
+ goto error;
 /* read initial info */
 for (;;) {
 if ((c = fgetc(self->logfp)) == EOF) {
 eof_error(self);
- break;
+ goto error;
 }
 if (c != WHAT_ADD_INFO) {
 ungetc(c, self->logfp);
@@ -1383,13 +1379,15 @@
 else
 PyErr_SetString(PyExc_RuntimeError,
 "unexpected error");
- break;
+ goto error;
 }
 }
 }
 }
- finally:
 return (PyObject *) self;
+ error:
+ Py_DECREF(self);
+ return NULL;
 }
 
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /