Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 May 2026 17:58:06 +0000
From:      Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 29351335704e - main - tftp: Close files when we're done with them
Message-ID:  <6a10992e.3a302.1469c66d@gitrepo.freebsd.org>

index | next in thread | raw e-mail

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);
 	}
 }
 


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a10992e.3a302.1469c66d>