Skip to content

Commit 9e770d6

Browse files
committed
_msgpack_buffer_add_new_chunk zero-out the newly allocated tail
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.
1 parent 96b21a4 commit 9e770d6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/msgpack/buffer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_bu
257257
} else {
258258
chunk = xmalloc(sizeof(msgpack_buffer_chunk_t));
259259
}
260-
memset(chunk, 0, sizeof(msgpack_buffer_chunk_t));
261260
return chunk;
262261
}
263262

@@ -295,6 +294,7 @@ static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b)
295294
before_tail->next = nc;
296295
nc->next = &b->tail;
297296
}
297+
memset(&b->tail, 0, sizeof(msgpack_buffer_chunk_t));
298298
}
299299

300300
static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE string)
@@ -315,7 +315,6 @@ static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE s
315315
b->tail.first = (char*) data;
316316
b->tail.last = (char*) data + length;
317317
b->tail.mapped_string = mapped_string;
318-
b->tail.mem = NULL;
319318

320319
/* msgpack_buffer_writable_size should return 0 for mapped chunk */
321320
b->tail_buffer_end = b->tail.last;
@@ -344,6 +343,8 @@ static inline void* _msgpack_buffer_chunk_malloc(
344343
msgpack_buffer_t* b, msgpack_buffer_chunk_t* c,
345344
size_t required_size, size_t* allocated_size)
346345
{
346+
c->mapped_string = NO_MAPPED_STRING;
347+
347348
if(required_size <= MSGPACK_RMEM_PAGE_SIZE) {
348349
c->rmem = true;
349350

0 commit comments

Comments
 (0)