mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-22 00:19:19 +01:00
python: Add memory error check.
This commit is contained in:
parent
85778494e4
commit
fe26df5355
@ -46,6 +46,8 @@ cdef class Packer(object):
|
|||||||
def __cinit__(self):
|
def __cinit__(self):
|
||||||
cdef int buf_size = 1024*1024
|
cdef int buf_size = 1024*1024
|
||||||
self.pk.buf = <char*> malloc(buf_size);
|
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.buf_size = buf_size
|
||||||
self.pk.length = 0
|
self.pk.length = 0
|
||||||
|
|
||||||
@ -300,7 +302,9 @@ cdef class Unpacker(object):
|
|||||||
new_size = buf_size*2
|
new_size = buf_size*2
|
||||||
buf = <char*>realloc(buf, new_size)
|
buf = <char*>realloc(buf, new_size)
|
||||||
if buf == NULL:
|
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
|
buf_size = new_size
|
||||||
|
|
||||||
memcpy(buf + tail, <char*>(_buf), _buf_len)
|
memcpy(buf + tail, <char*>(_buf), _buf_len)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user