From ae09d4d3ef56bcd390ba433cfb36135b4d723ae1 Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Thu, 23 Nov 2023 03:08:49 -0500 Subject: [PATCH] redis-check-aof.c: Avoid leaking file handle if file is zero bytes (#12797) If fopen() is successful, but redis_fstat() determines the file is zero bytes, the file handle stored in fp will leak. This change closes the filehandle stored in fp if the file is zero bytes. An FD leak on a tool like redis-check-aof isn't an issue (it'll exit soon anyway). This is just a cleanup. --- src/redis-check-aof.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/redis-check-aof.c b/src/redis-check-aof.c index 616177a8b7..d39ac6109f 100644 --- a/src/redis-check-aof.c +++ b/src/redis-check-aof.c @@ -238,6 +238,7 @@ int checkSingleAof(char *aof_filename, char *aof_filepath, int last_file, int fi off_t size = sb.st_size; if (size == 0) { + fclose(fp); return AOF_CHECK_EMPTY; }