git: 29351335704e - main - tftp: Close files when we're done with them
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 22 May 2026 17:58:06 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=29351335704e39ce3ca09c528d534c7898bbdc2c
commit 29351335704e39ce3ca09c528d534c7898bbdc2c
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-05-22 17:57:12 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-05-22 17:57:12 +0000
tftp: Close files when we're done with them
Also, delete the file we created if receiving it failed.
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D57071
---
usr.bin/tftp/main.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
index 9b7ea7155d82..a26561eaa982 100644
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -584,8 +584,11 @@ get(int argc, char *argv[])
if (verbose)
printf("getting from %s:%s to %s [%s]\n",
hostname, src, cp, mode);
- if (recvfile(peer, port, fd, src, mode) != 0)
+ if (recvfile(peer, port, fd, src, mode) != 0) {
+ (void) unlink(cp);
txrx_error = 1;
+ }
+ close(fd);
break;
}
cp = tail(src); /* new .. jdg */
@@ -597,8 +600,11 @@ get(int argc, char *argv[])
if (verbose)
printf("getting from %s:%s to %s [%s]\n",
hostname, src, cp, mode);
- if (recvfile(peer, port, fd, src, mode) != 0)
+ if (recvfile(peer, port, fd, src, mode) != 0) {
+ (void) unlink(cp);
txrx_error = 1;
+ }
+ close(fd);
}
}