From c8a10631d14dfad768b0b924e8dfb240af858dcb Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 22 Jul 2010 16:06:27 +0200 Subject: [PATCH] fix rare condition where 'key' would already be destroyed while is was needed later on --- src/vm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vm.c b/src/vm.c index 1aaa57eb5..073cace2f 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1075,6 +1075,11 @@ int dontWaitForSwappedKey(redisClient *c, robj *key) { listIter li; struct dictEntry *de; + /* The key object might be destroyed when deleted from the c->io_keys + * list (and the "key" argument is physically the same object as the + * object inside the list), so we need to protect it. */ + incrRefCount(key); + /* Remove the key from the list of keys this client is waiting for. */ listRewind(c->io_keys,&li); while ((ln = listNext(&li)) != NULL) { @@ -1095,6 +1100,7 @@ int dontWaitForSwappedKey(redisClient *c, robj *key) { if (listLength(l) == 0) dictDelete(c->db->io_keys,key); + decrRefCount(key); return listLength(c->io_keys) == 0; }