mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-06-27 19:20:50 +00:00
Harden Unpacker.__init__ re-entry cleanup to prevent buffer/context leaks (#687)
This commit is contained in:
parent
7df7136e20
commit
77395c19a5
2 changed files with 42 additions and 3 deletions
|
|
@ -317,9 +317,6 @@ cdef class Unpacker:
|
|||
cdef Py_ssize_t max_buffer_size
|
||||
cdef uint64_t stream_offset
|
||||
|
||||
def __cinit__(self):
|
||||
self.buf = NULL
|
||||
|
||||
def __dealloc__(self):
|
||||
unpack_clear(&self.ctx)
|
||||
PyMem_Free(self.buf)
|
||||
|
|
@ -338,6 +335,12 @@ cdef class Unpacker:
|
|||
Py_ssize_t max_ext_len=-1):
|
||||
cdef const char *cerr=NULL
|
||||
|
||||
unpack_clear(&self.ctx)
|
||||
unpack_init(&self.ctx)
|
||||
if self.buf != NULL:
|
||||
PyMem_Free(self.buf)
|
||||
self.buf = NULL
|
||||
|
||||
self.object_hook = object_hook
|
||||
self.object_pairs_hook = object_pairs_hook
|
||||
self.list_hook = list_hook
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue