diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-24 23:06:25 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-06-24 23:06:25 (GMT) |
commit | 174799912f1529c6cbd227f83fa5345b5f474f31 (patch) | |
tree | e3c201b2cc79dbd9b1082e60066c9deab9d003f5 /Python | |
parent | 94fbaac58def9d3c289e5904e82a1598d4577f9a (diff) | |
download | cpython-174799912f1529c6cbd227f83fa5345b5f474f31.zip cpython-174799912f1529c6cbd227f83fa5345b5f474f31.tar.gz cpython-174799912f1529c6cbd227f83fa5345b5f474f31.tar.bz2 |
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)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/getargs.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 272ce19..686eac5 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; } |