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:
parent
3572cd6b8f
commit
01046395ac
1 changed files with 4 additions and 1 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue