summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornot-a-robot <not-a-robot@rediger.net>2016-12-09 11:12:16 +0100
committerGitHub <noreply@github.com>2016-12-09 11:12:16 +0100
commitb4f9fc1a2aa1d991b014b03b0369fd36a089e39c (patch)
tree71b1029fbb1fb843aaf585720dfff8cbea47210f
parent8636d90821f9656c62e92e78d93a380fc00fc0f7 (diff)
parentcbb956567b715acd3022eb07a46eb6e23cd038e1 (diff)
Auto merge of #468 - paul-scott:master, r=badboy
Prevented uv adapter from calling write when context has been freed The `redisLibuvPoll` function can be called with both the `UV_READABLE` and `UV_WRITABLE` flags set at the same time. Calling `redisAsyncHandleRead` can lead to a disconnect and the context being cleaned up/freed. If this happens then `redisAsyncHandleWrite` should not be called otherwise memory read/write errors and duplicate freeing will occur. These changes prevent this from happening by having the `redisLibuvCleanup` callback indicate that the context has been cleaned. This is done indirectly by setting the context to a null pointer, maybe someone can come up with a cleaner way.
-rw-r--r--adapters/libuv.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/adapters/libuv.h b/adapters/libuv.h
index 3cdf3d3..ff08c25 100644
--- a/adapters/libuv.h
+++ b/adapters/libuv.h
@@ -20,10 +20,10 @@ static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
return;
}
- if (events & UV_READABLE) {
+ if (p->context != NULL && (events & UV_READABLE)) {
redisAsyncHandleRead(p->context);
}
- if (events & UV_WRITABLE) {
+ if (p->context != NULL && (events & UV_WRITABLE)) {
redisAsyncHandleWrite(p->context);
}
}
@@ -83,6 +83,7 @@ static void on_close(uv_handle_t* handle) {
static void redisLibuvCleanup(void *privdata) {
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
+ p->context = NULL; // indicate that context might no longer exist
uv_close((uv_handle_t*)&p->handle, on_close);
}