diff --git a/src/rdb.c b/src/rdb.c index 6420e9924..73bc143f5 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -1314,7 +1314,7 @@ werr: /* Write error. */ int rdbSave(char *filename, rdbSaveInfo *rsi) { char tmpfile[256]; char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */ - FILE *fp; + FILE *fp = NULL; rio rdb; int error = 0; @@ -1343,10 +1343,11 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) { } /* Make sure data will not remain on the OS's output buffers */ - if (fflush(fp) == EOF) goto werr; - if (fsync(fileno(fp)) == -1) goto werr; - if (fclose(fp) == EOF) goto werr; - + if (fflush(fp)) goto werr; + if (fsync(fileno(fp))) goto werr; + if (fclose(fp)) { fp = NULL; goto werr; } + fp = NULL; + /* Use RENAME to make sure the DB file is changed atomically only * if the generate DB file is ok. */ if (rename(tmpfile,filename) == -1) { @@ -1372,7 +1373,7 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) { werr: serverLog(LL_WARNING,"Write error saving DB on disk: %s", strerror(errno)); - fclose(fp); + if (fp) fclose(fp); unlink(tmpfile); stopSaving(0); return C_ERR;