Skip to content
Browse files

Free old buffer properly

  • Loading branch information...
1 parent 106e841 commit 05af17d3f7844a4b94964c0b1e91a722c82bbfb5 @evanphx evanphx committed Sep 25, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 ext/puma_http11/io_buffer.c
View
10 ext/puma_http11/io_buffer.c
@@ -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++) {

0 comments on commit 05af17d

Please sign in to comment.
Something went wrong with that request. Please try again.