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

Make `object->string' explicitly close its string output port.

* libguile/strports.c (scm_object_to_string): Close PORT before
  returning the resulting string.
This commit is contained in:
Ludovic Courtès 2011-03-06 22:13:10 +01:00
parent ceed7709be
commit 8b26337712

View file

@ -374,7 +374,7 @@ SCM_DEFINE (scm_object_to_string, "object->string", 1, 1, 0,
"argument @var{printer} (default: @code{write}).")
#define FUNC_NAME s_scm_object_to_string
{
SCM port;
SCM port, result;
if (!SCM_UNBNDP (printer))
SCM_VALIDATE_PROC (2, printer);
@ -387,7 +387,17 @@ SCM_DEFINE (scm_object_to_string, "object->string", 1, 1, 0,
else
scm_call_2 (printer, obj, port);
return scm_strport_to_string (port);
result = scm_strport_to_string (port);
/* Explicitly close PORT so that the iconv CDs associated with it are
deallocated right away. This is important because CDs use a lot of
memory that's not visible to the GC, so not freeing them can lead
to almost large heap usage. See
<http://wingolog.org/archives/2011/02/25/ports-weaks-gc-and-dark-matter>
for details. */
scm_close_port (port);
return result;
}
#undef FUNC_NAME