From 583f6747b3fbea1e35cf973825f89221d48667b2 Mon Sep 17 00:00:00 2001 From: Jessie Murray Date: Sun, 1 Aug 2021 13:55:18 -0700 Subject: [PATCH] Avoid dereferencing NULL in pool_on_disconnect pool_on_disconnect was assuming a pool object was attached and logging using its server object. It also checked for NULL, but too late. --- src/pool.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pool.c b/src/pool.c index 4836d27..741c7da 100644 --- a/src/pool.c +++ b/src/pool.c @@ -96,6 +96,11 @@ pool_on_disconnect(const redisAsyncContext *ac, int status) { struct pool *p = ac->data; int i = 0; + + if(p == NULL) { /* no need to clean anything here. */ + return; + } + if (status != REDIS_OK) { char format[] = "Error disconnecting: %s"; size_t msg_sz = sizeof(format) - 2 + ((ac && ac->errstr) ? strlen(ac->errstr) : 6); @@ -107,10 +112,6 @@ pool_on_disconnect(const redisAsyncContext *ac, int status) { } } - if(p == NULL) { /* no need to clean anything here. */ - return; - } - /* remove from the pool */ for(i = 0; i < p->count; ++i) { if(p->ac[i] == ac) {