Fix for issue #45
This commit is contained in:
parent
159a83ab8a
commit
5f5b3d9787
12
hiredis.c
12
hiredis.c
@ -77,7 +77,7 @@ void freeReplyObject(void *reply) {
|
|||||||
case REDIS_REPLY_INTEGER:
|
case REDIS_REPLY_INTEGER:
|
||||||
break; /* Nothing to free */
|
break; /* Nothing to free */
|
||||||
case REDIS_REPLY_ARRAY:
|
case REDIS_REPLY_ARRAY:
|
||||||
if (r->elements > 0 && r->element != NULL) {
|
if (r->element != NULL) {
|
||||||
for (j = 0; j < r->elements; j++)
|
for (j = 0; j < r->elements; j++)
|
||||||
if (r->element[j] != NULL)
|
if (r->element[j] != NULL)
|
||||||
freeReplyObject(r->element[j]);
|
freeReplyObject(r->element[j]);
|
||||||
@ -133,10 +133,12 @@ static void *createArrayObject(const redisReadTask *task, int elements) {
|
|||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
r->element = calloc(elements,sizeof(redisReply*));
|
if (elements > 0) {
|
||||||
if (r->element == NULL) {
|
r->element = calloc(elements,sizeof(redisReply*));
|
||||||
freeReplyObject(r);
|
if (r->element == NULL) {
|
||||||
return NULL;
|
freeReplyObject(r);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r->elements = elements;
|
r->elements = elements;
|
||||||
|
12
test.c
12
test.c
@ -247,6 +247,18 @@ static void test_reply_reader(void) {
|
|||||||
assert(ret == REDIS_ERR);
|
assert(ret == REDIS_ERR);
|
||||||
ret = redisReaderGetReply(reader,&reply);
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
test_cond(ret == REDIS_ERR && reply == NULL);
|
test_cond(ret == REDIS_ERR && reply == NULL);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
/* Regression test for issue #45 on GitHub. */
|
||||||
|
test("Don't do empty allocation for empty multi bulk: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader,(char*)"*0\r\n",4);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_ARRAY &&
|
||||||
|
((redisReply*)reply)->elements == 0);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *test_create_string(const redisReadTask *task, char *str, size_t len) {
|
static void *test_create_string(const redisReadTask *task, char *str, size_t len) {
|
||||||
|
Loading…
Reference in New Issue
Block a user