8000 python: Add memory error check. · scott2b/msgpack-python@b453385 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit b453385

Browse files
committed
python: Add memory error check.
1 parent 47b0c27 commit b453385

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

msgpack/_msgpack.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ cdef class Packer(object):
4646
def __cinit__(self):
4747
cdef int buf_size = 1024*1024
4848
self.pk.buf = <char*> malloc(buf_size);
49+
if self.pk.buf == NULL:
50+
raise MemoryError("Unable to allocate internal buffer.")
4951
self.pk.buf_size = buf_size
5052
self.pk.length = 0
5153

@@ -300,7 +302,9 @@ cdef class Unpacker(object):
300302
new_size = buf_size*2
301303
buf = <char*>realloc(buf, new_size)
302304
if buf == NULL:
303-
raise MemoryError("Unable to enlarge internal buffer.") # self.buf still holds old buffer and will be freed during obj destruction
305+
# self.buf still holds old buffer and will be freed during
306+
# obj destruction
307+
raise MemoryError("Unable to enlarge internal buffer.")
304308
buf_size = new_size
305309

306310
memcpy(buf + tail, <char*>(_buf), _buf_len)

0 commit comments

Comments
 (0)
0