Don't leak file descriptor on syncWithMaster().

Close #3804.
This commit is contained in:
antirez 2017-02-20 10:18:41 +01:00
parent f917e0da4c
commit 76d87f47c7

View File

@ -1568,7 +1568,7 @@ int slaveTryPartialResynchronization(int fd, int read_reply) {
* establish a connection with the master. */ * establish a connection with the master. */
void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) { void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
char tmpfile[256], *err = NULL; char tmpfile[256], *err = NULL;
int dfd, maxtries = 5; int dfd = -1, maxtries = 5;
int sockerr = 0, psync_result; int sockerr = 0, psync_result;
socklen_t errlen = sizeof(sockerr); socklen_t errlen = sizeof(sockerr);
UNUSED(el); UNUSED(el);
@ -1832,6 +1832,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
error: error:
aeDeleteFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE); aeDeleteFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE);
if (dfd != -1) close(dfd);
close(fd); close(fd);
server.repl_transfer_s = -1; server.repl_transfer_s = -1;
server.repl_state = REPL_STATE_CONNECT; server.repl_state = REPL_STATE_CONNECT;