diff --git a/src/replication.c b/src/replication.c index e49c76788..236b4a1f4 100644 --- a/src/replication.c +++ b/src/replication.c @@ -3332,7 +3332,6 @@ error: * establish a connection with the primary. */ void syncWithPrimary(connection *conn) { char tmpfile[256], *err = NULL; - int dfd = -1, maxtries = 5; int psync_result; /* If this event fired after the user turned the instance into a primary @@ -3601,6 +3600,7 @@ void syncWithPrimary(connection *conn) { /* Prepare a suitable temp file for bulk transfer */ if (!useDisklessLoad()) { + int dfd = -1, maxtries = 5; while (maxtries--) { snprintf(tmpfile, 256, "temp-%d.%ld.rdb", (int)server.unixtime, (long int)getpid()); dfd = open(tmpfile, O_CREAT | O_WRONLY | O_EXCL, 0644); @@ -3657,7 +3657,6 @@ no_response_error: /* Handle receiveSynchronousResponse() error when primary has /* Fall through to regular error handling */ error: - if (dfd != -1) close(dfd); connClose(conn); server.repl_transfer_s = NULL; if (server.repl_rdb_transfer_s) {