Skip to content

Commit

Permalink
free client's multi state when it becomes dirty
Browse files Browse the repository at this point in the history
Signed-off-by: zhaozhao.zz <[email protected]>
  • Loading branch information
soloestoy committed Aug 28, 2024
1 parent 6172907 commit 0e25895
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void discardTransaction(client *c) {
* Should be called every time there is an error while queueing a command. */
void flagTransaction(client *c) {
if (c->flag.multi) c->flag.dirty_exec = 1;
if (c->mstate.commands) {
freeClientMultiState(c);
initClientMultiState(c);
}
}

void multiCommand(client *c) {
Expand Down Expand Up @@ -391,6 +395,10 @@ void touchWatchedKey(serverDb *db, robj *key) {
}

c->flag.dirty_cas = 1;
if (c->mstate.commands) {
freeClientMultiState(c);
initClientMultiState(c);
}
/* As the client is marked as dirty, there is no point in getting here
* again in case that key (or others) are modified again (or keep the
* memory overhead till EXEC). */
Expand Down Expand Up @@ -442,6 +450,10 @@ void touchAllWatchedKeysInDb(serverDb *emptied, serverDb *replaced_with) {
}
client *c = wk->client;
c->flag.dirty_cas = 1;
if (c->mstate.commands) {
freeClientMultiState(c);
initClientMultiState(c);
}
/* Note - we could potentially call unwatchAllKeys for this specific client in order to reduce
* the total number of iterations. BUT this could also free the current next entry pointer
* held by the iterator and can lead to use-after-free. */
Expand Down

0 comments on commit 0e25895

Please sign in to comment.