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:
+4
-1
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user