Kaydet (Commit) fe2e8395 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

Fix reference leaks introduced by the patch for issue #5308.

üst 8cedb89c
...@@ -88,7 +88,7 @@ w_more(int c, WFILE *p) ...@@ -88,7 +88,7 @@ w_more(int c, WFILE *p)
} }
static void 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) { if (p->fp != NULL) {
fwrite(s, 1, n, p->fp); fwrite(s, 1, n, p->fp);
...@@ -141,6 +141,13 @@ w_long64(long x, WFILE *p) ...@@ -141,6 +141,13 @@ w_long64(long x, WFILE *p)
# define W_SIZE w_long # define W_SIZE w_long
#endif #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 /* 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 2**15; for the sake of portability we'll always read and write them in base
exactly 2**15. */ exactly 2**15. */
...@@ -338,9 +345,7 @@ w_object(PyObject *v, WFILE *p) ...@@ -338,9 +345,7 @@ w_object(PyObject *v, WFILE *p)
else { else {
w_byte(TYPE_STRING, p); w_byte(TYPE_STRING, p);
} }
n = PyString_GET_SIZE(v); w_pstring(PyBytes_AS_STRING(v), PyString_GET_SIZE(v), p);
W_SIZE(n, p);
w_string(PyString_AS_STRING(v), n, p);
} }
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
else if (PyUnicode_CheckExact(v)) { else if (PyUnicode_CheckExact(v)) {
...@@ -352,9 +357,7 @@ w_object(PyObject *v, WFILE *p) ...@@ -352,9 +357,7 @@ w_object(PyObject *v, WFILE *p)
return; return;
} }
w_byte(TYPE_UNICODE, p); w_byte(TYPE_UNICODE, p);
n = PyString_GET_SIZE(utf8); w_pstring(PyString_AS_STRING(utf8), PyString_GET_SIZE(utf8), p);
W_SIZE(n, p);
w_string(PyString_AS_STRING(utf8), n, p);
Py_DECREF(utf8); Py_DECREF(utf8);
} }
#endif #endif
...@@ -441,8 +444,7 @@ w_object(PyObject *v, WFILE *p) ...@@ -441,8 +444,7 @@ w_object(PyObject *v, WFILE *p)
PyBufferProcs *pb = v->ob_type->tp_as_buffer; PyBufferProcs *pb = v->ob_type->tp_as_buffer;
w_byte(TYPE_STRING, p); w_byte(TYPE_STRING, p);
n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s); n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
W_SIZE(n, p); w_pstring(s, n, p);
w_string(s, n, p);
} }
else { else {
w_byte(TYPE_UNKNOWN, p); w_byte(TYPE_UNKNOWN, p);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment