1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-29 08:20:20 +02:00

fix a couple leaks in ports.c. thanks valgrind!

* libguile/ports.c (scm_i_remove_port): Fix a case in which ports
  explictly closed via close-port would leak their iconv_t data.
  (scm_set_port_encoding_x): scm_i_set_port_encoding_x strdups its
  argument, so we need to free the locale encoding of the incoming str.
This commit is contained in:
Andy Wingo 2011-02-18 19:28:33 +01:00
parent 6854c32480
commit 3e05fc0466

View file

@ -661,6 +661,19 @@ scm_i_remove_port (SCM port)
scm_port_non_buffer (p);
p->putback_buf = NULL;
p->putback_buf_size = 0;
if (p->input_cd != (iconv_t) -1)
{
iconv_close (p->input_cd);
p->input_cd = (iconv_t) -1;
}
if (p->output_cd != (iconv_t) -1)
{
iconv_close (p->output_cd);
p->output_cd = (iconv_t) -1;
}
SCM_SETPTAB_ENTRY (port, 0);
scm_hashq_remove_x (scm_i_port_weak_hash, port);
@ -2099,6 +2112,7 @@ SCM_DEFINE (scm_set_port_encoding_x, "set-port-encoding!", 2, 0, 0,
enc_str = scm_to_locale_string (enc);
scm_i_set_port_encoding_x (port, enc_str);
free (enc_str);
return SCM_UNSPECIFIED;
}