Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
5f5b3d97
You need to sign in or sign up before continuing.
Commit
5f5b3d97
authored
Jun 09, 2011
by
Pieter Noordhuis
Browse files
Fix for issue #45
parent
159a83ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
hiredis.c
View file @
5f5b3d97
...
...
@@ -77,7 +77,7 @@ void freeReplyObject(void *reply) {
case
REDIS_REPLY_INTEGER
:
break
;
/* Nothing to free */
case
REDIS_REPLY_ARRAY
:
if
(
r
->
elements
>
0
&&
r
->
element
!=
NULL
)
{
if
(
r
->
element
!=
NULL
)
{
for
(
j
=
0
;
j
<
r
->
elements
;
j
++
)
if
(
r
->
element
[
j
]
!=
NULL
)
freeReplyObject
(
r
->
element
[
j
]);
...
...
@@ -133,10 +133,12 @@ static void *createArrayObject(const redisReadTask *task, int elements) {
if
(
r
==
NULL
)
return
NULL
;
r
->
element
=
calloc
(
elements
,
sizeof
(
redisReply
*
));
if
(
r
->
element
==
NULL
)
{
freeReplyObject
(
r
);
return
NULL
;
if
(
elements
>
0
)
{
r
->
element
=
calloc
(
elements
,
sizeof
(
redisReply
*
));
if
(
r
->
element
==
NULL
)
{
freeReplyObject
(
r
);
return
NULL
;
}
}
r
->
elements
=
elements
;
...
...
test.c
View file @
5f5b3d97
...
...
@@ -247,6 +247,18 @@ static void test_reply_reader(void) {
assert
(
ret
==
REDIS_ERR
);
ret
=
redisReaderGetReply
(
reader
,
&
reply
);
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment