diff Modules/cStringIO.c @ 41500:0a6e537b8d96 2.5

Fix various minor issues discovered with static analysis using Visual Studio 2005 Team System. Removed obsolete comment, since .dll modules are no longer supported on windows, only .pyd.
author Kristján Valur Jónsson <kristjan@ccpgames.com>
date Sat, 21 Apr 2007 12:46:49 +0000
parents fb0c6a67a939
children 89c81fd7038e
line wrap: on
line diff
--- a/Modules/cStringIO.c	Sat Apr 21 12:20:09 2007 +0000
+++ b/Modules/cStringIO.c	Sat Apr 21 12:46:49 2007 +0000
@@ -339,13 +339,17 @@
         }
 
         if (position > self->buf_size) {
+                  char *newbuf;
                   self->buf_size*=2;
                   if (self->buf_size <= position) self->buf_size=position+1;
-		  self->buf = (char*) realloc(self->buf,self->buf_size);
-                  if (!self->buf) {
+		  newbuf = (char*) realloc(self->buf,self->buf_size);
+                  if (!newbuf) {
+                      free(self->buf);
+                      self->buf = 0;
                       self->buf_size=self->pos=0;
                       return PyErr_NoMemory();
                     }
+                  self->buf = newbuf;
           }
         else if (position < 0) position=0;
 
@@ -366,6 +370,7 @@
 O_cwrite(PyObject *self, const char *c, Py_ssize_t  l) {
         Py_ssize_t newl;
         Oobject *oself;
+        char *newbuf;
 
         if (!IO__opencheck(IOOOBJECT(self))) return -1;
         oself = (Oobject *)self;
@@ -377,12 +382,15 @@
 		    assert(newl + 1 < INT_MAX);
                     oself->buf_size = (int)(newl+1);
 	    }
-            oself->buf = (char*)realloc(oself->buf, oself->buf_size);
-	    if (!oself->buf) {
+            newbuf = (char*)realloc(oself->buf, oself->buf_size);
+	    if (!newbuf) {
                     PyErr_SetString(PyExc_MemoryError,"out of memory");
+                    free(oself->buf);
+                    oself->buf = 0;
                     oself->buf_size = oself->pos = 0;
                     return -1;
               }
+            oself->buf = newbuf;
           }
 
         memcpy(oself->buf+oself->pos,c,l);