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
This commit is contained in:
Moshe Kaplan 2023-11-23 03:06:13 -05:00 committed by GitHub
parent 157e5d47b5
commit 1c48d3dab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();