[Python-checkins] r61968 - python/trunk/Objects/bytesobject.c

neal.norwitz python-checkins at python.org
Thu Mar 27 05:40:08 CET 2008


Author: neal.norwitz
Date: Thu Mar 27 05:40:07 2008
New Revision: 61968

Modified:
   python/trunk/Objects/bytesobject.c
Log:
Fix memory leaks

Modified: python/trunk/Objects/bytesobject.c
==============================================================================
--- python/trunk/Objects/bytesobject.c	(original)
+++ python/trunk/Objects/bytesobject.c	Thu Mar 27 05:40:07 2008
@@ -2683,17 +2683,21 @@
         if (! _getbytevalue(item, &value)) {
             Py_DECREF(item);
             Py_DECREF(it);
+            PyMem_Free(buf);
             return NULL;
         }
         buf[len++] = value;
         Py_DECREF(item);
         if (len >= buf_size) {
+            char *new_buf;
             buf_size = len + (len >> 1) + 1;
-            buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char));
-            if (buf == NULL) {
+            new_buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char));
+            if (new_buf == NULL) {
                 Py_DECREF(it);
+                PyMem_Free(buf);
                 return PyErr_NoMemory();
             }
+            buf = new_buf;
         }
     }
     Py_DECREF(it);


More information about the Python-checkins mailing list