mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-06-19 06:02:09 +00:00
fix: avoid memory leak when decoding invalid nested arrays (#671)
This commit is contained in:
parent
378edc60f1
commit
4a07745675
3 changed files with 44 additions and 0 deletions
|
|
@ -322,6 +322,7 @@ cdef class Unpacker:
|
|||
self.buf = NULL
|
||||
|
||||
def __dealloc__(self):
|
||||
unpack_clear(&self.ctx)
|
||||
PyMem_Free(self.buf)
|
||||
self.buf = NULL
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,14 @@ static inline PyObject* unpack_data(unpack_context* ctx)
|
|||
|
||||
static inline void unpack_clear(unpack_context *ctx)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 1; i < ctx->top; i++) {
|
||||
Py_CLEAR(ctx->stack[i].obj);
|
||||
/* map_key holds a live reference only while waiting for the value */
|
||||
if (ctx->stack[i].ct == CT_MAP_VALUE) {
|
||||
Py_CLEAR(ctx->stack[i].map_key);
|
||||
}
|
||||
}
|
||||
Py_CLEAR(ctx->stack[0].obj);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue