git: 9b945635c147 - releng/13.4 - tail -F: fix crash

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 21 Aug 2024 16:00:03 UTC
The branch releng/13.4 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=9b945635c147feb4ac6ebf84bd19e149e9a10227

commit 9b945635c147feb4ac6ebf84bd19e149e9a10227
Author:     Andre Albsmeier <mail@fbsd2.e4m.org>
AuthorDate: 2024-08-19 07:54:24 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-08-21 15:59:21 +0000

    tail -F: fix crash
    
    PR:     280910
    Approved by:    re (cperciva)
    
    (cherry picked from commit 308399a179a49b7b858c725de10177fdb0502fd2)
    (cherry picked from commit 8dfa4e5b6ce2e22ef92c0ec13aa001994774c23f)
---
 usr.bin/tail/forward.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c
index a902e006afed..2edf8730e8b1 100644
--- a/usr.bin/tail/forward.c
+++ b/usr.bin/tail/forward.c
@@ -382,7 +382,8 @@ follow(file_info_t *files, enum STYLE style, off_t off)
 				    sb2.st_dev != file->st.st_dev ||
 				    sb2.st_nlink == 0) {
 					show(file);
-					fclose(file->fp);
+					if (file->fp != NULL)
+						fclose(file->fp);
 					file->fp = ftmp;
 					memcpy(&file->st, &sb2,
 					    sizeof(struct stat));