Unverified Commit fa751f9b authored by Moshe Kaplan's avatar Moshe Kaplan Committed by GitHub
Browse files

config.c: Avoid leaking file handle if file is 0 bytes (#12828)

If fopen() is successful and redis_fstat determines that the file is 0
bytes, the file handle stored in fp will leak. This change closes the
filehandle stored in fp if the file is 0 bytes.

Second attempt at fixing Coverity 390029

This is a follow-up to #12796
parent bef57153
...@@ -1128,7 +1128,14 @@ struct rewriteConfigState *rewriteConfigReadOldFile(char *path) { ...@@ -1128,7 +1128,14 @@ struct rewriteConfigState *rewriteConfigReadOldFile(char *path) {
int linenum = -1; int linenum = -1;
struct rewriteConfigState *state = rewriteConfigCreateState(); struct rewriteConfigState *state = rewriteConfigCreateState();
if (fp == NULL || sb.st_size == 0) return state; if (fp == NULL) {
return state;
}
if (sb.st_size == 0) {
fclose(fp);
return state;
}
/* Load the file content */ /* Load the file content */
sds config = sdsnewlen(SDS_NOINIT,sb.st_size); sds config = sdsnewlen(SDS_NOINIT,sb.st_size);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment