diff --git a/ChangeLog b/ChangeLog index 4d27c38ca1..86f9db71f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Sep 25 19:37:34 2014 Eric Wong + + * io.c (free_io_buffer): new function for a common pattern + (clear_readconv): use free_io_buffer + (rb_io_fptr_finalize): ditto + Thu Sep 25 07:51:07 2014 Ayumu AIZAWA * lib/matrix.rb: Fix docs. Patched by Ben Woodall. [GH-726] diff --git a/io.c b/io.c index 5909a0be50..876ae675a4 100644 --- a/io.c +++ b/io.c @@ -4325,6 +4325,15 @@ rb_io_fptr_cleanup(rb_io_t *fptr, int noraise) } } +static void +free_io_buffer(rb_io_buffer_t *buf) +{ + if (buf->ptr) { + ruby_sized_xfree(buf->ptr, (size_t)buf->capa); + buf->ptr = NULL; + } +} + static void clear_readconv(rb_io_t *fptr) { @@ -4332,10 +4341,7 @@ clear_readconv(rb_io_t *fptr) rb_econv_close(fptr->readconv); fptr->readconv = NULL; } - if (fptr->cbuf.ptr) { - free(fptr->cbuf.ptr); - fptr->cbuf.ptr = NULL; - } + free_io_buffer(&fptr->cbuf); } static void @@ -4363,14 +4369,8 @@ rb_io_fptr_finalize(rb_io_t *fptr) if (0 <= fptr->fd) rb_io_fptr_cleanup(fptr, TRUE); fptr->write_lock = 0; - if (fptr->rbuf.ptr) { - free(fptr->rbuf.ptr); - fptr->rbuf.ptr = 0; - } - if (fptr->wbuf.ptr) { - free(fptr->wbuf.ptr); - fptr->wbuf.ptr = 0; - } + free_io_buffer(&fptr->rbuf); + free_io_buffer(&fptr->wbuf); clear_codeconv(fptr); free(fptr); return 1;