mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
39bb54d89c
commit
405c4abb9f
2 changed files with 18 additions and 12 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Thu Sep 25 19:37:34 2014 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
|
* 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@gmail.com>
|
Thu Sep 25 07:51:07 2014 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
|
||||||
|
|
||||||
* lib/matrix.rb: Fix docs. Patched by Ben Woodall. [GH-726]
|
* lib/matrix.rb: Fix docs. Patched by Ben Woodall. [GH-726]
|
||||||
|
|
24
io.c
24
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
|
static void
|
||||||
clear_readconv(rb_io_t *fptr)
|
clear_readconv(rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
|
@ -4332,10 +4341,7 @@ clear_readconv(rb_io_t *fptr)
|
||||||
rb_econv_close(fptr->readconv);
|
rb_econv_close(fptr->readconv);
|
||||||
fptr->readconv = NULL;
|
fptr->readconv = NULL;
|
||||||
}
|
}
|
||||||
if (fptr->cbuf.ptr) {
|
free_io_buffer(&fptr->cbuf);
|
||||||
free(fptr->cbuf.ptr);
|
|
||||||
fptr->cbuf.ptr = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -4363,14 +4369,8 @@ rb_io_fptr_finalize(rb_io_t *fptr)
|
||||||
if (0 <= fptr->fd)
|
if (0 <= fptr->fd)
|
||||||
rb_io_fptr_cleanup(fptr, TRUE);
|
rb_io_fptr_cleanup(fptr, TRUE);
|
||||||
fptr->write_lock = 0;
|
fptr->write_lock = 0;
|
||||||
if (fptr->rbuf.ptr) {
|
free_io_buffer(&fptr->rbuf);
|
||||||
free(fptr->rbuf.ptr);
|
free_io_buffer(&fptr->wbuf);
|
||||||
fptr->rbuf.ptr = 0;
|
|
||||||
}
|
|
||||||
if (fptr->wbuf.ptr) {
|
|
||||||
free(fptr->wbuf.ptr);
|
|
||||||
fptr->wbuf.ptr = 0;
|
|
||||||
}
|
|
||||||
clear_codeconv(fptr);
|
clear_codeconv(fptr);
|
||||||
free(fptr);
|
free(fptr);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue