about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-05-18 21:55:44 +0100
committerArun Isaac2026-05-18 22:35:50 +0100
commit2801a3de19c69eae55822df7c4a1bf4f6e923da5 (patch)
tree00a1be71f1b35016ae6a93b4195ca2528734ffcc
parenta47a9e899383fba7e3488ae9d494af9caf0492fa (diff)
downloadkaagum-2801a3de19c69eae55822df7c4a1bf4f6e923da5.tar.gz
kaagum-2801a3de19c69eae55822df7c4a1bf4f6e923da5.tar.lz
kaagum-2801a3de19c69eae55822df7c4a1bf4f6e923da5.zip
Close files in binary-file? even when an exception is raised.
Prior to this, when an i/o-decoding-error was raised (as is expected
for binary files), we would exit the call-with-input-file procedure
non-locally, failing to close the port and leaving it up to the
garbage collector to close it later. This leaks file descriptors and
could result in a "Too many open files" error.

Change-Id: Ie21c1be41f6af62335dd8bf64aa603551e58cb4d
-rw-r--r--kaagum/tools/base.scm18
1 files changed, 9 insertions, 9 deletions
diff --git a/kaagum/tools/base.scm b/kaagum/tools/base.scm
index dd6107f..81faf3d 100644
--- a/kaagum/tools/base.scm
+++ b/kaagum/tools/base.scm
@@ -34,15 +34,15 @@
   "Return @code{#t} if @var{file} is a binary file. Else, return @code{#f}."
   ;; We use the following heuristic: If there are character decoding errors in
   ;; the first 10K characters, we assume that this is a binary file.
-  (guard (c ((or (i/o-decoding-error? c)
-                 (eq? (exception-kind c)
-                      'decoding-error))
-             #t))
-    (call-with-input-file file
-      (lambda (port)
-        (set-port-conversion-strategy! port 'error)
-        (get-string-n port (* 10 1024))))
-    #f))
+  (call-with-input-file file
+    (lambda (port)
+      (set-port-conversion-strategy! port 'error)
+      (guard (c ((or (i/o-decoding-error? c)
+                     (eq? (exception-kind c)
+                          'decoding-error))
+                 #t))
+        (get-string-n port (* 10 1024))
+        #f))))
 
 (define (make-regexp* pattern)
   "Like @code{make-regexp}, but report an error and abort if @var{pattern} is not a