From 1c48d3dab29ae0ef9f3c1df4c69b59cfd1a90e09 Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Thu, 23 Nov 2023 03:06:13 -0500 Subject: [PATCH] config.c: Avoid leaking file handle if redis_fstat() fails (#12796) If fopen() is successful, but redis_fstat() fails, the file handle stored in fp will leak. This change closes the filehandle stored in fp if redis_fstat() fails. Fixes Coverity 390029 --- src/config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 731b503b3..5684a082c 100644 --- a/src/config.c +++ b/src/config.c @@ -1120,7 +1120,10 @@ struct rewriteConfigState *rewriteConfigReadOldFile(char *path) { if (fp == NULL && errno != ENOENT) return NULL; struct redis_stat sb; - if (fp && redis_fstat(fileno(fp),&sb) == -1) return NULL; + if (fp && redis_fstat(fileno(fp),&sb) == -1) { + fclose(fp); + return NULL; + } int linenum = -1; struct rewriteConfigState *state = rewriteConfigCreateState();