[Python-checkins] cpython (2.7): Fix reference leaks introduced by the patch for issue #5308.

serhiy.storchaka python-checkins at python.org
Thu Jul 11 18:21:55 CEST 2013


http://hg.python.org/cpython/rev/1cf2c42af815
changeset:   84545:1cf2c42af815
branch:      2.7
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Jul 11 19:14:07 2013 +0300
summary:
  Fix reference leaks introduced by the patch for issue #5308.

files:
  Python/marshal.c |  20 +++++++++++---------
  1 files changed, 11 insertions(+), 9 deletions(-)


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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list