From 6208e9c31cd9038b1bcbe6c0176af54b1fc61612 Mon Sep 17 00:00:00 2001 From: Naveen Albert Date: Tue, 24 Sep 2024 07:29:59 -0400 Subject: [PATCH] astfd.c: Avoid calling fclose with NULL argument. Don't pass through a NULL argument to fclose, which is undefined behavior, and instead return -1 and set errno appropriately. This also avoids a compiler warning with glibc 2.38 and newer, as glibc commit 71d9e0fe766a3c22a730995b9d024960970670af added the nonnull attribute to this argument. Resolves: #900 (cherry picked from commit b29776a5b0518264333c4e78afe6dcbe226ff273) --- main/astfd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/astfd.c b/main/astfd.c index 78efe116ae..3dc62faff3 100644 --- a/main/astfd.c +++ b/main/astfd.c @@ -280,7 +280,8 @@ int __ast_fdleak_fclose(FILE *ptr) { int fd, res; if (!ptr) { - return fclose(ptr); + errno = EINVAL; + return -1; } fd = fileno(ptr); -- 2.47.2