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:
parent
106e84183c
commit
05af17d3f7
1 changed files with 8 additions and 2 deletions
|
@ -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++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue