mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
rdb.c: handle fclose error case differently to avoid double fclose (#7307)
When fclose would fail, the previous implementation would have attempted to do fclose again this can in theory lead to segfault. other changes: check for non-zero return value as failure rather than a specific error code. this doesn't fix a real bug, just a minor cleanup.
This commit is contained in:
parent
57709c4bc6
commit
323029baa6
11
src/rdb.c
11
src/rdb.c
@ -1314,7 +1314,7 @@ werr: /* Write error. */
|
|||||||
int rdbSave(char *filename, rdbSaveInfo *rsi) {
|
int rdbSave(char *filename, rdbSaveInfo *rsi) {
|
||||||
char tmpfile[256];
|
char tmpfile[256];
|
||||||
char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */
|
char cwd[MAXPATHLEN]; /* Current working dir path for error messages. */
|
||||||
FILE *fp;
|
FILE *fp = NULL;
|
||||||
rio rdb;
|
rio rdb;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
@ -1343,9 +1343,10 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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. */
|
||||||
@ -1372,7 +1373,7 @@ int rdbSave(char *filename, rdbSaveInfo *rsi) {
|
|||||||
|
|
||||||
werr:
|
werr:
|
||||||
serverLog(LL_WARNING,"Write error saving DB on disk: %s", strerror(errno));
|
serverLog(LL_WARNING,"Write error saving DB 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user