summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-03 12:57:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-03 12:57:49 (GMT)
commitb9765eec5cbc149120acb50646256cffde94d74f (patch)
tree88ec7474d898b34c898203e2031d5f47d5f81fbc /Modules/_io
parentab53ab0a843757d2a40bde1e00a80ea91bcf8402 (diff)
downloadcpython-b9765eec5cbc149120acb50646256cffde94d74f.zip
cpython-b9765eec5cbc149120acb50646256cffde94d74f.tar.gz
cpython-b9765eec5cbc149120acb50646256cffde94d74f.tar.bz2
Issue #15381: Try to fix refcount bug. Empty and 1-byte buffers are always shared.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/bytesio.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index ca5156b..1638f94 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -38,7 +38,8 @@ typedef struct {
return NULL; \
}
-#define SHARED_BUF(self) (Py_REFCNT((self)->buf) > 1)
+#define SHARED_BUF(self) (Py_REFCNT((self)->buf) > 1 || \
+ PyBytes_GET_SIZE((self)->buf) <= 1)
/* Internal routine to get a line from the buffer of a BytesIO
@@ -308,6 +309,7 @@ read_bytes(bytesio *self, Py_ssize_t size)
char *output;
assert(self->buf != NULL);
+ assert(size <= self->string_size);
if (size > 1 &&
self->pos == 0 && size == PyBytes_GET_SIZE(self->buf) &&
self->exports == 0) {