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
24e6166f
Commit
24e6166f
authored
Feb 11, 2019
by
Mark Nunberg
Browse files
libevent: fix invalid mem access on delete within callback enter
parent
5f633ac4
Changes
1
Show whitespace changes
Inline
Side-by-side
adapters/libevent.h
View file @
24e6166f
...
...
@@ -34,26 +34,49 @@
#include "../hiredis.h"
#include "../async.h"
#define REDIS_LIBEVENT_DELETED 0x01
#define REDIS_LIBEVENT_ENTERED 0x02
typedef
struct
redisLibeventEvents
{
redisAsyncContext
*
context
;
struct
event
*
ev
,
*
tmr
;
struct
event_base
*
base
;
struct
timeval
tv
;
short
flags
;
short
state
;
}
redisLibeventEvents
;
static
void
redisLibeventDestroy
(
redisLibeventEvents
*
e
)
{
free
(
e
);
}
static
void
redisLibeventHandler
(
int
fd
,
short
event
,
void
*
arg
)
{
((
void
)
fd
);
redisLibeventEvents
*
e
=
(
redisLibeventEvents
*
)
arg
;
if
(
event
&
EV_TIMEOUT
)
{
e
->
state
|=
REDIS_LIBEVENT_ENTERED
;
#define CHECK_DELETED() if (e->state & REDIS_LIBEVENT_DELETED) {\
redisLibeventDestroy(e);\
return; \
}
if
((
event
&
EV_TIMEOUT
)
&&
(
e
->
state
&
REDIS_LIBEVENT_DELETED
)
==
0
)
{
redisAsyncHandleTimeout
(
e
->
context
);
CHECK_DELETED
();
}
if
((
event
&
EV_READ
)
&&
e
->
context
)
{
if
((
event
&
EV_READ
)
&&
e
->
context
&&
(
e
->
state
&
REDIS_LIBEVENT_DELETED
)
==
0
)
{
redisAsyncHandleRead
(
e
->
context
);
CHECK_DELETED
();
}
if
((
event
&
EV_WRITE
)
&&
e
->
context
)
{
if
((
event
&
EV_WRITE
)
&&
e
->
context
&&
(
e
->
state
&
REDIS_LIBEVENT_DELETED
)
==
0
)
{
redisAsyncHandleWrite
(
e
->
context
);
CHECK_DELETED
();
}
e
->
state
&=
~
REDIS_LIBEVENT_ENTERED
;
#undef CHECK_DELETED
}
static
void
redisLibeventUpdate
(
void
*
privdata
,
short
flag
,
int
isRemove
)
{
...
...
@@ -98,8 +121,18 @@ static void redisLibeventDelWrite(void *privdata) {
static
void
redisLibeventCleanup
(
void
*
privdata
)
{
redisLibeventEvents
*
e
=
(
redisLibeventEvents
*
)
privdata
;
if
(
!
e
)
{
return
;
}
event_del
(
e
->
ev
);
event_free
(
e
->
ev
);
e
->
ev
=
NULL
;
if
(
e
->
state
&
REDIS_LIBEVENT_ENTERED
)
{
e
->
state
|=
REDIS_LIBEVENT_DELETED
;
}
else
{
free
(
e
);
}
}
static
void
redisLibeventSetTimeout
(
void
*
privdata
,
struct
timeval
tv
)
{
...
...
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