Redis Benchmark: fix possible usage of freed pointer (getRedisConfig)

Fixes issue #5912
This commit is contained in:
artix 2019-03-12 17:07:19 +01:00
parent 14cce99469
commit 95b932ffcf

View File

@ -247,11 +247,11 @@ static redisConfig *getRedisConfig(const char *ip, int port,
c = redisConnect(ip, port); c = redisConnect(ip, port);
else else
c = redisConnectUnix(hostsocket); c = redisConnectUnix(hostsocket);
if (c->err) { if (c == NULL || c->err) {
fprintf(stderr,"Could not connect to Redis at "); fprintf(stderr,"Could not connect to Redis at ");
if (hostsocket == NULL) char *err = (c != NULL ? c->errstr : "");
fprintf(stderr,"%s:%d: %s\n",ip,port,c->errstr); if (hostsocket == NULL) fprintf(stderr,"%s:%d: %s\n",ip,port,err);
else fprintf(stderr,"%s: %s\n",hostsocket,c->errstr); else fprintf(stderr,"%s: %s\n",hostsocket,err);
goto fail; goto fail;
} }
redisAppendCommand(c, "CONFIG GET %s", "save"); redisAppendCommand(c, "CONFIG GET %s", "save");
@ -276,18 +276,16 @@ static redisConfig *getRedisConfig(const char *ip, int port,
case 1: cfg->appendonly = sdsnew(value); break; case 1: cfg->appendonly = sdsnew(value); break;
} }
} }
if (reply) freeReplyObject(reply); freeReplyObject(reply);
if (c) redisFree(c); redisFree(c);
return cfg; return cfg;
fail: fail:
if (reply) freeReplyObject(reply);
if (c) redisFree(c);
zfree(cfg);
fprintf(stderr, "ERROR: failed to fetch CONFIG from "); fprintf(stderr, "ERROR: failed to fetch CONFIG from ");
if (c->connection_type == REDIS_CONN_TCP) if (hostsocket == NULL) fprintf(stderr, "%s:%d\n", ip, port);
fprintf(stderr, "%s:%d\n", c->tcp.host, c->tcp.port); else fprintf(stderr, "%s\n", hostsocket);
else if (c->connection_type == REDIS_CONN_UNIX) freeReplyObject(reply);
fprintf(stderr, "%s\n", c->unix_sock.path); redisFree(c);
zfree(cfg);
return NULL; return NULL;
} }
static void freeRedisConfig(redisConfig *cfg) { static void freeRedisConfig(redisConfig *cfg) {