FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix reference leaks introduced by the patch for issue #5308. · python-emscripten/cpython@a155d40 · GitHub

Repository navigation

Commit a155d40

Browse files
Fix reference leaks introduced by the patch for issue python#5308.
2 parents 4918560 + dfde215 commit a155d40

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

‎Python/marshal.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ w_more(int c, WFILE *p)
9797
}
9898

9999
static void
100-
w_string(char *s, Py_ssize_t n, WFILE *p)
100+
w_string(const char *s, Py_ssize_t n, WFILE *p)
101101
{
102102
if (p->fp != NULL) {
103103
fwrite(s, 1, n, p->fp);
@@ -141,6 +141,13 @@ w_long(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. */
@@ -384,9 +391,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
384391
}
385392
else if (PyBytes_CheckExact(v)) {
386393
W_TYPE(TYPE_STRING, p);
387-
n = PyBytes_GET_SIZE(v);
388-
W_SIZE(n, p);
389-
w_string(PyBytes_AS_STRING(v), n, p);
394+
w_pstring(PyBytes_AS_STRING(v), PyBytes_GET_SIZE(v), p);
390395
}
391396
else if (PyUnicode_CheckExact(v)) {
392397
PyObject *utf8;
@@ -400,9 +405,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
400405
W_TYPE(TYPE_INTERNED, p);
401406
else
402407
W_TYPE(TYPE_UNICODE, p);
403-
n = PyBytes_GET_SIZE(utf8);
404-
W_SIZE(n, p);
405-
w_string(PyBytes_AS_STRING(utf8), n, p);
408+
w_pstring(PyBytes_AS_STRING(utf8), PyBytes_GET_SIZE(utf8), p);
406409
Py_DECREF(utf8);
407410
}
408411
else if (PyTuple_CheckExact(v)) {
@@ -485,7 +488,6 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
485488
}
486489
else if (PyObject_CheckBuffer(v)) {
487490
/* Write unknown buffer-style objects as a string */
488-
char *s;
489491
Py_buffer view;
490492
if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) != 0) {
491493
w_byte(TYPE_UNKNOWN, p);
@@ -494,10 +496,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
494496
return;
495497
}
496498
W_TYPE(TYPE_STRING, p);
497-
n = view.len;
498-
s = view.buf;
499-
W_SIZE(n, p);
500-
w_string(s, n, p);
499+
w_pstring(view.buf, view.len, p);
501500
PyBuffer_Release(&view);
502501
}
503502
else {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL