Skip to content

Commit 4b8077f

Browse files
Fix reference leaks introduced by the patch for issue #5308.
1 parent 68a448c commit 4b8077f

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

Python/marshal.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ w_more(int c, WFILE *p)
8888
}
8989

9090
static void
91-
w_string(char *s, Py_ssize_t n, WFILE *p)
91+
w_string(const char *s, Py_ssize_t n, WFILE *p)
9292
{
9393
if (p->fp != NULL) {
9494
fwrite(s, 1, n, p->fp);
@@ -141,6 +141,13 @@ w_long64(long x, WFILE *p)
141141
# define W_SIZE w_long
142142
#endif
143143

144+
static void
145+
w_pstring(const char *s, Py_ssize_t n, WFILE *p)
146+
{
147+
W_SIZE(n, p);
148+
w_string(s, n, p);
149+
}
150+
144151
/* We assume that Python longs are stored internally in base some power of
145152
2**15; for the sake of portability we'll always read and write them in base
146153
exactly 2**15. */
@@ -338,9 +345,7 @@ w_object(PyObject *v, WFILE *p)
338345
else {
339346
w_byte(TYPE_STRING, p);
340347
}
341-
n = PyString_GET_SIZE(v);
342-
W_SIZE(n, p);
343-
w_string(PyString_AS_STRING(v), n, p);
348+
w_pstring(PyBytes_AS_STRING(v), PyString_GET_SIZE(v), p);
344349
}
345350
#ifdef Py_USING_UNICODE
346351
else if (PyUnicode_CheckExact(v)) {
@@ -352,9 +357,7 @@ w_object(PyObject *v, WFILE *p)
352357
return;
353358
}
354359
w_byte(TYPE_UNICODE, p);
355-
n = PyString_GET_SIZE(utf8);
356-
W_SIZE(n, p);
357-
w_string(PyString_AS_STRING(utf8), n, p);
360+
w_pstring(PyString_AS_STRING(utf8), PyString_GET_SIZE(utf8), p);
358361
Py_DECREF(utf8);
359362
}
360363
#endif
@@ -441,8 +444,7 @@ w_object(PyObject *v, WFILE *p)
441444
PyBufferProcs *pb = v->ob_type->tp_as_buffer;
442445
w_byte(TYPE_STRING, p);
443446
n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
444-
W_SIZE(n, p);
445-
w_string(s, n, p);
447+
w_pstring(s, n, p);
446448
}
447449
else {
448450
w_byte(TYPE_UNKNOWN, p);

0 commit comments

Comments
 (0)