1. Armin Rigo
  2. cpython-withatomic

Commits

Michael W. Hudson  committed e0a9f66

Backport (with Anthony's blessing (in fact he reminded me to do it :)):

Patches #1298449 and #1298499: Add some missing checks for error
returns in cStringIO.c. Thanks to Andrew Bennetts.

This must be a backport candidate.

  • Participants
  • Parent commits 68dbcbf
  • Branches 2.4

Comments (0)

Files changed (4)

File Lib/test/test_StringIO.py

View file
         f.seek(0)
         self.assertEqual(f.getvalue(), 'abc')
 
+    def test_writelines_error(self):
+        def errorGen():
+            yield 'a'
+            raise KeyboardInterrupt()
+        f = self.MODULE.StringIO()
+        self.assertRaises(KeyboardInterrupt, f.writelines, errorGen())
+
     def test_truncate(self):
         eq = self.assertEqual
         f = self.MODULE.StringIO()

File Misc/ACKS

View file
 Thomas Bellman
 Juan M. Bello Rivas
 Alexander Belopolsky
+Andrew Bennetts
 Andy Bensky
 Michel Van den Bergh
 Eric Beser

File Misc/NEWS

View file
 Extension Modules
 -----------------
 
+- Patches #1298449 and #1298499: Add some missing checks for error
+  returns in cStringIO.c.
+
 - Patch #1297028: fix segfault if call type on MultibyteCodec,
   MultibyteStreamReader, or MultibyteStreamWriter.
 

File Modules/cStringIO.c

View file
 		line = PyString_FromStringAndSize (output, n);
 		if (!line) 
                         goto err;
-		PyList_Append (result, line);
+		if (PyList_Append (result, line) == -1) {
+			Py_DECREF (line);
+			goto err;
+		}
 		Py_DECREF (line);
                 length += n;
                 if (hint > 0 && length >= hint)
 			Py_DECREF(it);
 			Py_DECREF(s);
 			return NULL;
-		}
-		Py_DECREF(s);
-	}
-	Py_DECREF(it);
-	Py_RETURN_NONE;
+               }
+               Py_DECREF(s);
+       }
+
+       Py_DECREF(it);
+
+       /* See if PyIter_Next failed */
+       if (PyErr_Occurred())
+               return NULL;
+
+       Py_RETURN_NONE;
 }
 
 static struct PyMethodDef O_methods[] = {