mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-06-19 06:02:09 +00:00
fix: eliminate memory leak when parsing incorrect nested arrays
This commit is contained in:
parent
0d600a3328
commit
406360b3a8
2 changed files with 9 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