Skip to content

Commit 1b627c1

Browse files
committed
Zero-out msgpack_buffer_chunk_t after allocation
Fix: #341 These struct contain a VALUE reference so if we don't zero it out, it could be pointing at a T_NONE or some other old object slot. Especially since we can re-use existing chunks.
1 parent ad67a61 commit 1b627c1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ext/msgpack/buffer.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,14 @@ bool _msgpack_buffer_read_all2(msgpack_buffer_t* b, char* buffer, size_t length)
251251

252252
static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_buffer_t* b)
253253
{
254-
msgpack_buffer_chunk_t* reuse = b->free_list;
255-
if(reuse == NULL) {
256-
return xmalloc(sizeof(msgpack_buffer_chunk_t));
254+
msgpack_buffer_chunk_t* chunk = b->free_list;
255+
if (chunk) {
256+
b->free_list = b->free_list->next;
257+
} else {
258+
chunk = xmalloc(sizeof(msgpack_buffer_chunk_t));
257259
}
258-
b->free_list = b->free_list->next;
259-
return reuse;
260+
memset(chunk, 0, sizeof(msgpack_buffer_chunk_t));
261+
return chunk;
260262
}
261263

262264
static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)

0 commit comments

Comments
 (0)