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
2602e1b6
Commit
2602e1b6
authored
May 29, 2014
by
Pieter Noordhuis
Browse files
Merge pull request #246 from dmelani/master
Less surprising behaviour in redisFree() and freeReplyObject()
parents
f225c276
21a1207a
Changes
2
Hide whitespace changes
Inline
Side-by-side
hiredis.c
View file @
2602e1b6
...
@@ -73,6 +73,9 @@ void freeReplyObject(void *reply) {
...
@@ -73,6 +73,9 @@ void freeReplyObject(void *reply) {
redisReply
*
r
=
reply
;
redisReply
*
r
=
reply
;
size_t
j
;
size_t
j
;
if
(
r
==
NULL
)
return
;
switch
(
r
->
type
)
{
switch
(
r
->
type
)
{
case
REDIS_REPLY_INTEGER
:
case
REDIS_REPLY_INTEGER
:
break
;
/* Nothing to free */
break
;
/* Nothing to free */
...
@@ -1001,6 +1004,8 @@ static redisContext *redisContextInit(void) {
...
@@ -1001,6 +1004,8 @@ static redisContext *redisContextInit(void) {
}
}
void
redisFree
(
redisContext
*
c
)
{
void
redisFree
(
redisContext
*
c
)
{
if
(
c
==
NULL
)
return
;
if
(
c
->
fd
>
0
)
if
(
c
->
fd
>
0
)
close
(
c
->
fd
);
close
(
c
->
fd
);
if
(
c
->
obuf
!=
NULL
)
if
(
c
->
obuf
!=
NULL
)
...
...
test.c
View file @
2602e1b6
...
@@ -318,6 +318,19 @@ static void test_reply_reader(void) {
...
@@ -318,6 +318,19 @@ static void test_reply_reader(void) {
redisReaderFree
(
reader
);
redisReaderFree
(
reader
);
}
}
static
void
test_free_null
(
void
)
{
void
*
redisContext
=
NULL
;
void
*
reply
=
NULL
;
test
(
"Don't fail when redisFree is passed a NULL value: "
);
redisFree
(
redisContext
);
test_cond
(
redisContext
==
NULL
);
test
(
"Don't fail when freeReplyObject is passed a NULL value: "
);
freeReplyObject
(
reply
);
test_cond
(
reply
==
NULL
);
}
static
void
test_blocking_connection_errors
(
void
)
{
static
void
test_blocking_connection_errors
(
void
)
{
redisContext
*
c
;
redisContext
*
c
;
...
@@ -702,6 +715,7 @@ int main(int argc, char **argv) {
...
@@ -702,6 +715,7 @@ int main(int argc, char **argv) {
test_format_commands
();
test_format_commands
();
test_reply_reader
();
test_reply_reader
();
test_blocking_connection_errors
();
test_blocking_connection_errors
();
test_free_null
();
printf
(
"
\n
Testing against TCP connection (%s:%d):
\n
"
,
cfg
.
tcp
.
host
,
cfg
.
tcp
.
port
);
printf
(
"
\n
Testing against TCP connection (%s:%d):
\n
"
,
cfg
.
tcp
.
host
,
cfg
.
tcp
.
port
);
cfg
.
type
=
CONN_TCP
;
cfg
.
type
=
CONN_TCP
;
...
@@ -723,6 +737,7 @@ int main(int argc, char **argv) {
...
@@ -723,6 +737,7 @@ int main(int argc, char **argv) {
test_blocking_connection
(
cfg
);
test_blocking_connection
(
cfg
);
}
}
if
(
fails
)
{
if
(
fails
)
{
printf
(
"*** %d TESTS FAILED ***
\n
"
,
fails
);
printf
(
"*** %d TESTS FAILED ***
\n
"
,
fails
);
return
1
;
return
1
;
...
...
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