Skip to content

Commit dbe6572

Browse files
committed
Merge pull request #155 from methane/fix/152
Decrease refcnt when error happend while unpacking
2 parents a329850 + 35a69ac commit dbe6572

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

msgpack/_unpacker.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ cdef extern from "unpack.h":
4747
execute_fn read_map_header
4848
void unpack_init(unpack_context* ctx)
4949
object unpack_data(unpack_context* ctx)
50+
void unpack_clear(unpack_context* ctx)
5051

5152
cdef inline init_ctx(unpack_context *ctx,
5253
object object_hook, object object_pairs_hook,
@@ -141,8 +142,8 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
141142
if off < buf_len:
142143
raise ExtraData(obj, PyBytes_FromStringAndSize(buf+off, buf_len-off))
143144
return obj
144-
else:
145-
raise UnpackValueError("Unpack failed: error = %s" % (ret,))
145+
unpack_clear(&ctx)
146+
raise UnpackValueError("Unpack failed: error = %d" % (ret,))
146147

147148

148149
def unpack(object stream, object object_hook=None, object list_hook=None,

msgpack/unpack_template.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ static inline PyObject* unpack_data(unpack_context* ctx)
7070
return (ctx)->stack[0].obj;
7171
}
7272

73+
static inline PyObject* unpack_clear(unpack_context *ctx)
74+
{
75+
Py_CLEAR(ctx->stack[0].obj);
76+
}
7377

7478
template <bool construct>
7579
static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize_t len, Py_ssize_t* off)

0 commit comments

Comments
 (0)