From 9f5c311e4561a855a1b6882c6003134fadab7d3b Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Tue, 28 Dec 2021 20:58:13 +0100 Subject: [PATCH] Do not call fclose() on a NULL pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The if clause is true if cache is NULL. man 3 fclose says: The behaviour of fclose() is undefined if the stream parameter is an illegal pointer, or is a descriptor already passed to a previous invo‐ cation of fclose(). Check if cache is NULL before calling fclose(). --- buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/buffer.c b/buffer.c index 083ecf6..f4a0377 100644 --- a/buffer.c +++ b/buffer.c @@ -707,7 +707,8 @@ readBufferCache(Buffer *buf) cache = fopen(buf->savecache, "r"); if (cache == NULL || fread1(clnum, cache) || fread1(tlnum, cache)) { - fclose(cache); + if (cache != NULL) + fclose(cache); buf->savecache = NULL; return -1; }