summaryrefslogtreecommitdiff
path: root/msgpack/_msgpack.pyx
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2011-01-10 20:47:23 +0900
committerINADA Naoki <songofacandy@gmail.com>2011-01-10 20:47:23 +0900
commitb453385d92e549204e7e1639f286589a38143061 (patch)
tree8949d9cdfde7ebc23fc8914643727fa1af2beb88 /msgpack/_msgpack.pyx
parent47b0c273bb70d34b253c9e908a3f2d55e99b8cef (diff)
downloadmsgpack-python-b453385d92e549204e7e1639f286589a38143061.tar.gz
python: Add memory error check.
Diffstat (limited to 'msgpack/_msgpack.pyx')
-rw-r--r--msgpack/_msgpack.pyx6
1 files changed, 5 insertions, 1 deletions
diff --git a/msgpack/_msgpack.pyx b/msgpack/_msgpack.pyx
index e48f8b2..9f817dd 100644
--- a/msgpack/_msgpack.pyx
+++ b/msgpack/_msgpack.pyx
@@ -46,6 +46,8 @@ cdef class Packer(object):
def __cinit__(self):
cdef int buf_size = 1024*1024
self.pk.buf = <char*> malloc(buf_size);
+ if self.pk.buf == NULL:
+ raise MemoryError("Unable to allocate internal buffer.")
self.pk.buf_size = buf_size
self.pk.length = 0
@@ -300,7 +302,9 @@ cdef class Unpacker(object):
new_size = buf_size*2
buf = <char*>realloc(buf, new_size)
if buf == NULL:
- raise MemoryError("Unable to enlarge internal buffer.") # self.buf still holds old buffer and will be freed during obj destruction
+ # self.buf still holds old buffer and will be freed during
+ # obj destruction
+ raise MemoryError("Unable to enlarge internal buffer.")
buf_size = new_size
memcpy(buf + tail, <char*>(_buf), _buf_len)