]> granicus.if.org Git - python/commitdiff
Merged revisions 67797 via svnmerge from
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Mon, 15 Dec 2008 22:16:00 +0000 (22:16 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Mon, 15 Dec 2008 22:16:00 +0000 (22:16 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67797 | amaury.forgeotdarc | 2008-12-15 22:47:57 +0100 (Mon, 15 Dec 2008) | 4 lines

  #3954: Fix error handling code in _hotshot.logreader

  Will port to 2.6. hotshot was deleted from python 3.
........

Lib/test/test_hotshot.py
Misc/NEWS
Modules/_hotshot.c

index 2751b3ffd490d5100196138208ddc4f9761f6c18..35ca6aa7f799fc12539541fcb08e03a1a6cc359e 100644 (file)
@@ -3,6 +3,8 @@ import hotshot.log
 import os
 import pprint
 import unittest
+import _hotshot
+import gc
 
 from test import test_support
 
@@ -124,6 +126,10 @@ class HotShotTestCase(unittest.TestCase):
             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)
 
index a3da314f86eab21df7e55eccbc290be5dd27ba42..43f5ce71431be57fe3d45d4125ef8744874d25e8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@ Core and Builtins
 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.
index 4c66e2a6a3c4a59ded78062860c3084d19ad7f7b..a36cd50f0f65aa53d80a47c3cf1740b30fa4d186 100644 (file)
@@ -1357,20 +1357,16 @@ hotshot_logreader(PyObject *unused, PyObject *args)
             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 @@ hotshot_logreader(PyObject *unused, PyObject *args)
                     else
                         PyErr_SetString(PyExc_RuntimeError,
                                         "unexpected error");
-                    break;
+                    goto error;
                 }
             }
         }
     }
- finally:
     return (PyObject *) self;
+  error:
+    Py_DECREF(self);
+    return NULL;
 }