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
d7e3268f
Commit
d7e3268f
authored
Jan 22, 2013
by
Henri Doreau
Browse files
Prevent AsyncConnect from crashing on memory allocation failures.
parent
814be4f5
Changes
1
Hide whitespace changes
Inline
Side-by-side
async.c
View file @
d7e3268f
...
@@ -102,7 +102,12 @@ static dictType callbackDict = {
...
@@ -102,7 +102,12 @@ static dictType callbackDict = {
};
};
static
redisAsyncContext
*
redisAsyncInitialize
(
redisContext
*
c
)
{
static
redisAsyncContext
*
redisAsyncInitialize
(
redisContext
*
c
)
{
redisAsyncContext
*
ac
=
realloc
(
c
,
sizeof
(
redisAsyncContext
));
redisAsyncContext
*
ac
;
ac
=
realloc
(
c
,
sizeof
(
redisAsyncContext
));
if
(
ac
==
NULL
)
return
NULL
;
c
=
&
(
ac
->
c
);
c
=
&
(
ac
->
c
);
/* The regular connect functions will always set the flag REDIS_CONNECTED.
/* The regular connect functions will always set the flag REDIS_CONNECTED.
...
@@ -150,6 +155,11 @@ redisAsyncContext *redisAsyncConnect(const char *ip, int port) {
...
@@ -150,6 +155,11 @@ redisAsyncContext *redisAsyncConnect(const char *ip, int port) {
return
NULL
;
return
NULL
;
ac
=
redisAsyncInitialize
(
c
);
ac
=
redisAsyncInitialize
(
c
);
if
(
ac
==
NULL
)
{
redisFree
(
c
);
return
NULL
;
}
__redisAsyncCopyError
(
ac
);
__redisAsyncCopyError
(
ac
);
return
ac
;
return
ac
;
}
}
...
@@ -194,6 +204,9 @@ static int __redisPushCallback(redisCallbackList *list, redisCallback *source) {
...
@@ -194,6 +204,9 @@ static int __redisPushCallback(redisCallbackList *list, redisCallback *source) {
/* Copy callback from stack to heap */
/* Copy callback from stack to heap */
cb
=
malloc
(
sizeof
(
*
cb
));
cb
=
malloc
(
sizeof
(
*
cb
));
if
(
cb
==
NULL
)
return
REDIS_ERR_OOM
;
if
(
source
!=
NULL
)
{
if
(
source
!=
NULL
)
{
memcpy
(
cb
,
source
,
sizeof
(
*
cb
));
memcpy
(
cb
,
source
,
sizeof
(
*
cb
));
cb
->
next
=
NULL
;
cb
->
next
=
NULL
;
...
...
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