From 01046395accac9b6de5930bc827d3b08a54a7842 Mon Sep 17 00:00:00 2001 From: Kevin Ryde Date: Sat, 31 Jul 2004 01:19:26 +0000 Subject: [PATCH] (scm_copy_file): Avoid fd leak when destination file cannot be opened. --- libguile/filesys.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libguile/filesys.c b/libguile/filesys.c index e27bdca99..fa8cd18e1 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -1424,7 +1424,10 @@ SCM_DEFINE (scm_copy_file, "copy-file", 2, 0, 0, newfd = open (SCM_STRING_CHARS (newfile), O_WRONLY | O_CREAT | O_TRUNC, oldstat.st_mode & 07777); if (newfd == -1) - SCM_SYSERROR; + { + close (oldfd); + SCM_SYSERROR; + } while ((n = read (oldfd, buf, sizeof buf)) > 0) if (write (newfd, buf, n) != n)