From 3e05fc04668f2e2c0f0aa989d7adf11bef49ec84 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 18 Feb 2011 19:28:33 +0100 Subject: [PATCH] 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. --- libguile/ports.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libguile/ports.c b/libguile/ports.c index b65650e95..6a51ddc3c 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -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; }