Skip to content

Commit

Permalink
_msgpack_buffer_add_new_chunk zero-out the newly allocated tail
Browse files Browse the repository at this point in the history
Fix: #342

Reseting the memory in _msgpack_buffer_alloc_new_chunk was pointless
because the previous `tail` is immediately copied into it, and it's
the `tail` that is then used by the caller. So it's the `tail` we
should zero-out.
  • Loading branch information
byroot committed Jul 12, 2023
1 parent 96b21a4 commit 9e770d6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ext/msgpack/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ 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;
}

Expand Down Expand Up @@ -295,6 +294,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 +315,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 +343,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

0 comments on commit 9e770d6

Please sign in to comment.