From fe26df5355a97ce2ad52c56e464de531e652063b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 10 Jan 2011 20:47:23 +0900 Subject: [PATCH] python: Add memory error check. --- python/msgpack/_msgpack.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index e48f8b25..9f817ddd 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -46,6 +46,8 @@ cdef class Packer(object): def __cinit__(self): cdef int buf_size = 1024*1024 self.pk.buf = 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 = 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, (_buf), _buf_len)