Skip to content

Commit 8ba8702

Browse files
committed
Don't pre-allocate strings larger than the buffered size
1 parent 199e88f commit 8ba8702

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ext/msgpack/unpacker.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ static int read_raw_body_cont(msgpack_unpacker_t* uk)
336336
size_t length = uk->reading_raw_remaining;
337337

338338
if(uk->reading_raw == Qnil) {
339-
uk->reading_raw = rb_str_buf_new(length);
339+
size_t buffered_size = msgpack_buffer_all_readable_size(UNPACKER_BUFFER_(uk));
340+
uk->reading_raw = rb_str_buf_new(length > buffered_size ? buffered_size : length);
340341
}
341342

342343
do {

0 commit comments

Comments
 (0)