fix double fclose in aofrewrite (#7919)

minor fix for a bug which happen on error handling code
and doesn't look like it could have caused any real harm
(fd number wouldn't have been reused yet)

(cherry picked from commit ee8cb472a781e42ec7b10c6a88d258a3399ca34f)
This commit is contained in:
Wen Hui 2020-10-19 08:32:18 -04:00 committed by Oran Agra
parent c55bc96dc6
commit 4807eeef21

View File

@ -1426,7 +1426,7 @@ werr:
* are inserted using a single command. */ * are inserted using a single command. */
int rewriteAppendOnlyFile(char *filename) { int rewriteAppendOnlyFile(char *filename) {
rio aof; rio aof;
FILE *fp; FILE *fp = NULL;
char tmpfile[256]; char tmpfile[256];
char byte; char byte;
@ -1503,9 +1503,10 @@ int rewriteAppendOnlyFile(char *filename) {
goto werr; goto werr;
/* Make sure data will not remain on the OS's output buffers */ /* Make sure data will not remain on the OS's output buffers */
if (fflush(fp) == EOF) goto werr; if (fflush(fp)) goto werr;
if (fsync(fileno(fp)) == -1) goto werr; if (fsync(fileno(fp))) goto werr;
if (fclose(fp) == EOF) goto werr; if (fclose(fp)) { fp = NULL; goto werr; }
fp = NULL;
/* Use RENAME to make sure the DB file is changed atomically only /* Use RENAME to make sure the DB file is changed atomically only
* if the generate DB file is ok. */ * if the generate DB file is ok. */
@ -1521,7 +1522,7 @@ int rewriteAppendOnlyFile(char *filename) {
werr: werr:
serverLog(LL_WARNING,"Write error writing append only file on disk: %s", strerror(errno)); serverLog(LL_WARNING,"Write error writing append only file on disk: %s", strerror(errno));
fclose(fp); if (fp) fclose(fp);
unlink(tmpfile); unlink(tmpfile);
stopSaving(0); stopSaving(0);
return C_ERR; return C_ERR;