Do not call fclose() on a NULL pointer

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().
This commit is contained in:
Rene Kita
2021-12-28 20:58:13 +01:00
parent 1365cc1ecc
commit 9f5c311e45

View File

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