summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2017-09-06 12:08:54 +0200
committerStefan Behnel <stefan_ml@behnel.de>2017-09-06 12:08:54 +0200
commitbaeb5be4c2a183e6410dc07707b96e8347eb615e (patch)
treead278a2876e0eb7550d7ad6527d19ea0a29b5223
parentc6d0a5c8025771856812d4060b15d7aa2fbbb576 (diff)
downloadcython-baeb5be4c2a183e6410dc07707b96e8347eb615e.tar.gz
Release buffer on validation errors. My guess is that we previously just leaked the buffer owner in that case.
-rw-r--r--Cython/Utility/Buffer.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Cython/Utility/Buffer.c b/Cython/Utility/Buffer.c
index 19c1d9d61..e4419c754 100644
--- a/Cython/Utility/Buffer.c
+++ b/Cython/Utility/Buffer.c
@@ -742,7 +742,11 @@ static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
return 0;
}
buf->buf = NULL;
- if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail;
+ if (__Pyx_GetBuffer(obj, buf, flags) == -1) {
+ __Pyx_ZeroBuffer(buf);
+ return -1;
+ }
+ // From this point on, we have acquired the buffer and must release it on errors.
if (buf->ndim != nd) {
PyErr_Format(PyExc_ValueError,
"Buffer has wrong number of dimensions (expected %d, got %d)",
@@ -764,7 +768,7 @@ static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
return 0;
fail:;
- __Pyx_ZeroBuffer(buf);
+ __Pyx_SafeReleaseBuffer(buf);
return -1;
}