diff --git a/src/config.cpp b/src/config.cpp index c2e6ef73c..1237c1d43 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -487,7 +487,21 @@ void loadServerConfigFromString(char *config) { !strcasecmp(argv[0],"replicaof")) && argc == 3) { slaveof_linenum = linenum; if (!strcasecmp(argv[1], "no") && !strcasecmp(argv[2], "one")) { - listRelease(g_pserver->masters); + if (listLength(g_pserver->masters)) { + listIter li; + listNode *ln; + listRewind(g_pserver->masters, &li); + while ((ln = listNext(&li))) + { + struct redisMaster *mi = (struct redisMaster*)listNodeValue(ln); + zfree(mi->masterauth); + zfree(mi->masteruser); + zfree(mi->repl_transfer_tmpfile); + delete mi->staleKeyMap; + zfree(mi); + listDelNode(g_pserver->masters, ln); + } + } continue; } char *ptr; diff --git a/tests/integration/replication-active.tcl b/tests/integration/replication-active.tcl index cd7acd991..d50a66f6b 100644 --- a/tests/integration/replication-active.tcl +++ b/tests/integration/replication-active.tcl @@ -301,3 +301,20 @@ start_server {tags {"active-repl"} overrides {active-replica yes}} { } } } + +start_server {tags {"active-repl"} overrides {active-replica yes}} { + set master [srv 0 client] + set master_host [srv 0 host] + set master_port [srv 0 port] + test {REPLICAOF no one in config properly clears master list} { + start_server [list overrides [list "replicaof" "$master_host $master_port" "replicaof" "no one" "replicaof" "$master_host $master_port"]] { + wait_for_condition 50 100 { + [string match {*role:slave*} [[srv 0 client] info replication]] && + [string match "*master_host:$master_host*" [[srv 0 client] info replication]] && + [string match "*master_port:$master_port*" [[srv 0 client] info replication]] + } else { + fail "Replica did not properly connect to master" + } + } + } +}