Skip to content

Commit

Permalink
Merge pull request #342 from Shopify/zero-buffer-chunks-on-alloc
Browse files Browse the repository at this point in the history
Zero-out msgpack_buffer_chunk_t after allocation
  • Loading branch information
byroot committed Jun 29, 2023
2 parents ad67a61 + 1b627c1 commit 96b21a4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ext/msgpack/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,14 @@ bool _msgpack_buffer_read_all2(msgpack_buffer_t* b, char* buffer, size_t length)

static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_buffer_t* b)
{
msgpack_buffer_chunk_t* reuse = b->free_list;
if(reuse == NULL) {
return xmalloc(sizeof(msgpack_buffer_chunk_t));
msgpack_buffer_chunk_t* chunk = b->free_list;
if (chunk) {
b->free_list = b->free_list->next;
} else {
chunk = xmalloc(sizeof(msgpack_buffer_chunk_t));
}
b->free_list = b->free_list->next;
return reuse;
memset(chunk, 0, sizeof(msgpack_buffer_chunk_t));
return chunk;
}

static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
Expand Down

0 comments on commit 96b21a4

Please sign in to comment.