summaryrefslogtreecommitdiffstats
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-02 17:12:43 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-02 17:12:43 (GMT)
commit679e9d36f78de3ac18abaaddbcf4f73fcef55b7e (patch)
tree79bb8e94300dbb8ccb5eb2743a898149a62130ea /Python/marshal.c
parentb2b18632ce5f8067b2925f4ba2cf783479759ab4 (diff)
downloadcpython-679e9d36f78de3ac18abaaddbcf4f73fcef55b7e.zip
cpython-679e9d36f78de3ac18abaaddbcf4f73fcef55b7e.tar.gz
cpython-679e9d36f78de3ac18abaaddbcf4f73fcef55b7e.tar.bz2
Issue #14172: Fix reference leak when marshalling a buffer-like object (other than a bytes object).
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 094f732..7b1af44 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -411,11 +411,12 @@ w_object(PyObject *v, WFILE *p)
else if (PyObject_CheckBuffer(v)) {
/* Write unknown buffer-style objects as a string */
char *s;
- PyBufferProcs *pb = v->ob_type->tp_as_buffer;
Py_buffer view;
- if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) {
+ if (PyObject_GetBuffer(v, &view, PyBUF_SIMPLE) != 0) {
w_byte(TYPE_UNKNOWN, p);
+ p->depth--;
p->error = WFERR_UNMARSHALLABLE;
+ return;
}
w_byte(TYPE_STRING, p);
n = view.len;
@@ -427,8 +428,7 @@ w_object(PyObject *v, WFILE *p)
}
w_long((long)n, p);
w_string(s, (int)n, p);
- if (pb->bf_releasebuffer != NULL)
- (*pb->bf_releasebuffer)(v, &view);
+ PyBuffer_Release(&view);
}
else {
w_byte(TYPE_UNKNOWN, p);