diff --git a/src/adlist.c b/src/adlist.c index f171d3ec..2fb61a6f 100644 --- a/src/adlist.c +++ b/src/adlist.c @@ -52,10 +52,8 @@ list *listCreate(void) return list; } -/* Free the whole list. - * - * This function can't fail. */ -void listRelease(list *list) +/* Remove all the elements from the list without destroying the list itself. */ +void listEmpty(list *list) { unsigned long len; listNode *current, *next; @@ -68,6 +66,16 @@ void listRelease(list *list) zfree(current); current = next; } + list->head = list->tail = NULL; + list->len = 0; +} + +/* Free the whole list. + * + * This function can't fail. */ +void listRelease(list *list) +{ + listEmpty(list); zfree(list); } diff --git a/src/adlist.h b/src/adlist.h index be322552..e457a979 100644 --- a/src/adlist.h +++ b/src/adlist.h @@ -72,6 +72,7 @@ typedef struct list { /* Prototypes */ list *listCreate(void); void listRelease(list *list); +void listEmpty(list *list); list *listAddNodeHead(list *list, void *value); list *listAddNodeTail(list *list, void *value); list *listInsertNode(list *list, listNode *old_node, void *value, int after); diff --git a/src/replication.c b/src/replication.c index 1828eb8b..6be5d263 100644 --- a/src/replication.c +++ b/src/replication.c @@ -2119,13 +2119,17 @@ void replicationCacheMaster(client *c) { /* Unlink the client from the server structures. */ unlinkClient(c); - /* Fix the master specific fields: we want to discard to non processed - * query buffers and non processed offsets, including pending - * transactions. */ + /* Reset the master client so that's ready to accept new commands: + * we want to discard te non processed query buffers and non processed + * offsets, including pending transactions, already populated arguments, + * pending outputs to the master. */ sdsclear(server.master->querybuf); sdsclear(server.master->pending_querybuf); server.master->read_reploff = server.master->reploff; if (c->flags & CLIENT_MULTI) discardTransaction(c); + listEmpty(c->reply); + c->bufpos = 0; + resetClient(c); /* Save the master. Server.master will be set to null later by * replicationHandleMasterDisconnection(). */