ruby-changes:35630
From: normal <ko1@a...>
Date: Thu, 25 Sep 2014 19:40:49 +0900 (JST)
Subject: [ruby-changes:35630] normal:r47712 (trunk): io.c: common function to free IO buffers
normal 2014-09-25 19:40:37 +0900 (Thu, 25 Sep 2014) New Revision: 47712 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47712 Log: 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 Modified files: trunk/ChangeLog trunk/io.c Index: ChangeLog =================================================================== --- ChangeLog (revision 47711) +++ ChangeLog (revision 47712) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Sep 25 19:37:34 2014 Eric Wong <e@8...> + + * 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 <ayumu.aizawa@g...> * lib/matrix.rb: Fix docs. Patched by Ben Woodall. [GH-726] Index: io.c =================================================================== --- io.c (revision 47711) +++ io.c (revision 47712) @@ -4326,16 +4326,22 @@ rb_io_fptr_cleanup(rb_io_t *fptr, int no https://github.com/ruby/ruby/blob/trunk/io.c#L4326 } 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) https://github.com/ruby/ruby/blob/trunk/io.c#L4369 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/