Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_msgpack_buffer_add_new_chunk zero-out the newly allocated tail #343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/msgpack/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_bu
} else {
chunk = xmalloc(sizeof(msgpack_buffer_chunk_t));
}
memset(chunk, 0, sizeof(msgpack_buffer_chunk_t));
return chunk;
}

static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
{
if(b->head == &b->tail) {
if(b->tail.first == NULL) {
/* empty buffer */
/* The buffer is empty, we can just use the embeded tail directly */
memset(&b->tail, 0, sizeof(msgpack_buffer_chunk_t));
return;
}

Expand Down Expand Up @@ -295,6 +295,7 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
before_tail->next = nc;
nc->next = &b->tail;
}
memset(&b->tail, 0, sizeof(msgpack_buffer_chunk_t));
}

static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE string)
Expand All @@ -315,7 +316,6 @@ static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE s
b->tail.first = (char*) data;
b->tail.last = (char*) data + length;
b->tail.mapped_string = mapped_string;
b->tail.mem = NULL;

/* msgpack_buffer_writable_size should return 0 for mapped chunk */
b->tail_buffer_end = b->tail.last;
Expand Down Expand Up @@ -344,6 +344,8 @@ static inline void* _msgpack_buffer_chunk_malloc(
msgpack_buffer_t* b, msgpack_buffer_chunk_t* c,
size_t required_size, size_t* allocated_size)
{
c->mapped_string = NO_MAPPED_STRING;

if(required_size <= MSGPACK_RMEM_PAGE_SIZE) {
c->rmem = true;

Expand Down