mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-07-13 04:30:29 +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:
parent
ceed7709be
commit
8b26337712
1 changed files with 12 additions and 2 deletions
|
@ -374,7 +374,7 @@ SCM_DEFINE (scm_object_to_string, "object->string", 1, 1, 0,
|
||||||
"argument @var{printer} (default: @code{write}).")
|
"argument @var{printer} (default: @code{write}).")
|
||||||
#define FUNC_NAME s_scm_object_to_string
|
#define FUNC_NAME s_scm_object_to_string
|
||||||
{
|
{
|
||||||
SCM port;
|
SCM port, result;
|
||||||
|
|
||||||
if (!SCM_UNBNDP (printer))
|
if (!SCM_UNBNDP (printer))
|
||||||
SCM_VALIDATE_PROC (2, printer);
|
SCM_VALIDATE_PROC (2, printer);
|
||||||
|
@ -387,7 +387,17 @@ SCM_DEFINE (scm_object_to_string, "object->string", 1, 1, 0,
|
||||||
else
|
else
|
||||||
scm_call_2 (printer, obj, port);
|
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
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue