]> granicus.if.org Git - python/commitdiff
Issue #8926: getargs.c: release the buffer on error
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 24 Jun 2010 23:06:25 +0000 (23:06 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 24 Jun 2010 23:06:25 +0000 (23:06 +0000)
 - "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

index 272ce19a971b7d9a6cbd857a5891f590abf579d0..686eac532f69a077a6b86df468334f9337542297 100644 (file)
@@ -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;
         }