Skip to content

Commit ef2f24b

Browse files
authored
Merge pull request #328 from Shopify/fix-double-free-issues
_msgpack_rmem_alloc2: reset `head.pages` pointer before allocating them.
2 parents 21799f1 + f7e7652 commit ef2f24b

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
@@ -68,6 +68,7 @@ void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm)
6868
/* move head to array */
6969
*c = pm->head;
7070

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

0 commit comments

Comments
 (0)