Skip to content

Commit f7e7652

Browse files
committed
_msgpack_rmem_alloc2: reset head.pages pointer before allocating them.
`xmalloc` may trigger GC, if it does, some buffers may be freed by ruby and if they were in the previous head, they'll free themselves out of the head. Fix: #327
1 parent 51da8d8 commit f7e7652

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Fix a possible double-free issue when GC triggers inside `_msgpack_rmem_alloc2`.
12
* `Unpacker#feed` now always directly read in provided strings instead of copying content in its buffer.
23
* `Unpacker#feed` is now an alias of `Unpacker#feed_reference`.
34
* Implement `Factory::Pool#unpacker` and `Factory::Pool#packer` to allow for more precise serialization.

ext/msgpack/rmem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
7070
pm->head = *c;
7171
*c = tmp;
7272

73+
pm->head.pages = NULL; /* make sure we don't point to another chunk's pages in case xmalloc triggers GC */
7374
pm->head.mask = 0xffffffff & (~1); /* "& (~1)" means first chunk is already allocated */
7475
pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32);
7576

0 commit comments

Comments
 (0)