Blame SOURCES/00186-memory-leak-marshalc.patch

c8ca20
--- Python-2.7.5/Python/marshal.c	2013-05-12 05:32:53.000000000 +0200
c8ca20
+++ /home/rkuska/hg/cpython/Python/marshal.c	2013-07-18 10:33:26.392486235 +0200
c8ca20
@@ -88,7 +88,7 @@
c8ca20
 }
c8ca20
 
c8ca20
 static void
c8ca20
-w_string(char *s, Py_ssize_t n, WFILE *p)
c8ca20
+w_string(const char *s, Py_ssize_t n, WFILE *p)
c8ca20
 {
c8ca20
     if (p->fp != NULL) {
c8ca20
         fwrite(s, 1, n, p->fp);
c8ca20
@@ -141,6 +141,13 @@
c8ca20
 # define W_SIZE  w_long
c8ca20
 #endif
c8ca20
 
c8ca20
+static void
c8ca20
+w_pstring(const char *s, Py_ssize_t n, WFILE *p)
c8ca20
+{
c8ca20
+        W_SIZE(n, p);
c8ca20
+        w_string(s, n, p);
c8ca20
+}
c8ca20
+
c8ca20
 /* We assume that Python longs are stored internally in base some power of
c8ca20
    2**15; for the sake of portability we'll always read and write them in base
c8ca20
    exactly 2**15. */
c8ca20
@@ -338,9 +345,7 @@
c8ca20
         else {
c8ca20
             w_byte(TYPE_STRING, p);
c8ca20
         }
c8ca20
-        n = PyString_GET_SIZE(v);
c8ca20
-        W_SIZE(n, p);
c8ca20
-        w_string(PyString_AS_STRING(v), n, p);
c8ca20
+        w_pstring(PyBytes_AS_STRING(v), PyString_GET_SIZE(v), p);
c8ca20
     }
c8ca20
 #ifdef Py_USING_UNICODE
c8ca20
     else if (PyUnicode_CheckExact(v)) {
c8ca20
@@ -352,9 +357,7 @@
c8ca20
             return;
c8ca20
         }
c8ca20
         w_byte(TYPE_UNICODE, p);
c8ca20
-        n = PyString_GET_SIZE(utf8);
c8ca20
-        W_SIZE(n, p);
c8ca20
-        w_string(PyString_AS_STRING(utf8), n, p);
c8ca20
+        w_pstring(PyString_AS_STRING(utf8), PyString_GET_SIZE(utf8), p);
c8ca20
         Py_DECREF(utf8);
c8ca20
     }
c8ca20
 #endif
c8ca20
@@ -441,8 +444,7 @@
c8ca20
         PyBufferProcs *pb = v->ob_type->tp_as_buffer;
c8ca20
         w_byte(TYPE_STRING, p);
c8ca20
         n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
c8ca20
-        W_SIZE(n, p);
c8ca20
-        w_string(s, n, p);
c8ca20
+        w_pstring(s, n, p);
c8ca20
     }
c8ca20
     else {
c8ca20
         w_byte(TYPE_UNKNOWN, p);