diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-25 10:40:37 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-25 10:40:37 +0000 |
commit | 405c4abb9f382c935b04c48f22b51b3f3970f71a (patch) | |
tree | 806dd34e5204c012effe74cd4057fefcc7e09be8 /io.c | |
parent | 39bb54d89c93e4e488fb13a375e9097eec5ad9a7 (diff) | |
download | ruby-405c4abb9f382c935b04c48f22b51b3f3970f71a.tar.gz |
io.c: common function to free IO buffers
This also allows easier tracking of freed memory for systems
without malloc_usable_size, and also makes future changes
to freeing buffer memory easier-to-implement.
* io.c (free_io_buffer): new function for a common pattern
(clear_readconv): use free_io_buffer
(rb_io_fptr_finalize): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -4326,16 +4326,22 @@ 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) { if (fptr->readconv) { 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; |