summaryrefslogtreecommitdiff
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-02 18:12:43 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-02 18:12:43 +0100
commit0d7d8b127609e91a96e87941e246e9ffab7b25e4 (patch)
treef09b30cf5559b102bba236d3dbc45c26af0d0d62 /Python/marshal.c
parent5222a16d8417a3d99636983b4dcbabea72561c68 (diff)
downloadcpython-0d7d8b127609e91a96e87941e246e9ffab7b25e4.tar.gz
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 094f732382..7b1af44f99 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);