summaryrefslogtreecommitdiff
path: root/libguile/strports.c
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2011-03-06 22:13:10 +0100
committerLudovic Courtès <ludo@gnu.org>2011-03-06 23:05:00 +0100
commit8b2633771269173b55e9808b030a9312e8554aef (patch)
treec148ba28aa0663f298ac189db329346c28d6a244 /libguile/strports.c
parentceed7709becfe64eaaff54aa445b09d1882d589d (diff)
downloadguile-8b2633771269173b55e9808b030a9312e8554aef.tar.gz
Make `object->string' explicitly close its string output port.
* libguile/strports.c (scm_object_to_string): Close PORT before returning the resulting string.
Diffstat (limited to 'libguile/strports.c')
-rw-r--r--libguile/strports.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libguile/strports.c b/libguile/strports.c
index 8a2cd5a8b..957c6a157 100644
--- a/libguile/strports.c
+++ b/libguile/strports.c
@@ -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