From 174799912f1529c6cbd227f83fa5345b5f474f31 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 24 Jun 2010 23:06:25 +0000 Subject: [PATCH] Issue #8926: getargs.c: release the buffer on error - "t#" format: don't get the buffer if the object is not a pinned buffer - getbuffer(): release the buffer on error (Commit based on r82206 from py3k) --- Python/getargs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Python/getargs.c b/Python/getargs.c index 272ce19a97..686eac532f 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1384,6 +1384,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, return converterr( "bytes or read-only character buffer", arg, msgbuf, bufsize); + if (pb->bf_releasebuffer) + return converterr( + "string or pinned buffer", + arg, msgbuf, bufsize); if (PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) != 0) return converterr("string or single-segment read-only buffer", @@ -1391,10 +1395,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, count = view.len; *p = view.buf; - if (pb->bf_releasebuffer) - return converterr( - "string or pinned buffer", - arg, msgbuf, bufsize); PyBuffer_Release(&view); @@ -1460,6 +1460,7 @@ getbuffer(PyObject *arg, Py_buffer *view, char **errmsg) return -1; } if (!PyBuffer_IsContiguous(view, 'C')) { + PyBuffer_Release(view); *errmsg = "contiguous buffer"; return -1; } -- 2.40.0