1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Free old buffer properly

This commit is contained in:
Evan Phoenix 2012-09-25 09:00:36 -07:00
parent 106e84183c
commit 05af17d3f7

View file

@ -46,14 +46,17 @@ static VALUE buf_append(VALUE self, VALUE str) {
if(new_size > b->size) {
size_t n = b->size + (b->size / 2);
uint8_t* top;
uint8_t* old;
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
top = malloc(new_size);
memcpy(top, b->top, used);
old = b->top;
memcpy(top, old, used);
b->top = top;
b->cur = top + used;
b->size = new_size;
free(old);
}
memcpy(b->cur, RSTRING_PTR(str), str_len);
@ -84,14 +87,17 @@ static VALUE buf_append2(int argc, VALUE* argv, VALUE self) {
if(new_size > b->size) {
size_t n = b->size + (b->size / 2);
uint8_t* top;
uint8_t* old;
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
top = malloc(new_size);
memcpy(top, b->top, used);
old = b->top;
memcpy(top, old, used);
b->top = top;
b->cur = top + used;
b->size = new_size;
free(old);
}
for(i = 0; i < argc; i++) {