1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00

(scm_copy_file): Avoid fd leak when destination file

cannot be opened.
This commit is contained in:
Kevin Ryde 2004-07-31 01:19:26 +00:00
parent 3572cd6b8f
commit 01046395ac

View file

@ -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, newfd = open (SCM_STRING_CHARS (newfile), O_WRONLY | O_CREAT | O_TRUNC,
oldstat.st_mode & 07777); oldstat.st_mode & 07777);
if (newfd == -1) if (newfd == -1)
{
close (oldfd);
SCM_SYSERROR; SCM_SYSERROR;
}
while ((n = read (oldfd, buf, sizeof buf)) > 0) while ((n = read (oldfd, buf, sizeof buf)) > 0)
if (write (newfd, buf, n) != n) if (write (newfd, buf, n) != n)