Merge pull request #741 from redis/redisgetreply-null

Free the reply in redisGetReply when passed NULL
This commit is contained in:
Michael Grunder 2019-12-18 13:45:01 -08:00 committed by GitHub
commit c96d492215
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -945,8 +945,13 @@ int redisGetReply(redisContext *c, void **reply) {
} while (aux == NULL);
}
/* Set reply object */
if (reply != NULL) *reply = aux;
/* Set reply or free it if we were passed NULL */
if (reply != NULL) {
*reply = aux;
} else {
freeReplyObject(aux);
}
return REDIS_OK;
}

5
test.c
View File

@ -591,6 +591,11 @@ static void test_blocking_connection(struct config config) {
strcasecmp(reply->element[1]->str,"pong") == 0);
freeReplyObject(reply);
/* Make sure passing NULL to redisGetReply is safe */
test("Can pass NULL to redisGetReply: ");
assert(redisAppendCommand(c, "PING") == REDIS_OK);
test_cond(redisGetReply(c, NULL) == REDIS_OK);
disconnect(c, 0);
}