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
redis
Commits
1e78681d
Commit
1e78681d
authored
Oct 22, 2019
by
antirez
Browse files
Modules hooks: fix a leak and a few more issues.
parent
b9af7e24
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
1e78681d
...
@@ -328,23 +328,6 @@ static struct RedisModuleForkInfo {
...
@@ -328,23 +328,6 @@ static struct RedisModuleForkInfo {
* the start and end of an RDB or AOF save, the change of role in replication,
* the start and end of an RDB or AOF save, the change of role in replication,
* and similar other events. */
* and similar other events. */
#define REDISMODULE_EVENT_ID_REPLICATION_ROLE_CHANGED 0
#define REDISMODULE_EVENT_ID_RDB_SAVE_START 1
#define REDISMODULE_EVENT_ID_RDB_SAVE_END 2
#define REDISMODULE_EVENT_ID_AOF_REWRITE_START 3
#define REDISMODULE_EVENT_ID_AOF_REWRITE_END 4
#define REDISMODULE_EVENT_ID_FLUSHDB_START 5
#define REDISMODULE_EVENT_ID_FLUSHDB_END 6
#define REDISMODULE_EVENT_ID_LOADING_START 7
#define REDISMODULE_EVENT_ID_LOADING_END 8
#define REDISMODULE_EVENT_ID_CLIENT_CONNNECTED 9
#define REDISMODULE_EVENT_ID_CLIENT_DISCONNECTED 10
#define REDISMODULE_EVENT_ID_SERVER_SHUTDOWN 11
#define REDISMODULE_EVENT_ID_REPLICA_ONLINE 12
#define REDISMODULE_EVENT_ID_REPLICA_OFFLINE 13
#define REDISMODULE_EVENT_ID_MASTER_LINK_UP 14
#define REDISMODULE_EVENT_ID_MASTER_LINK_DOWN 15
typedef struct RedisModuleEventListener {
typedef struct RedisModuleEventListener {
RedisModule *module;
RedisModule *module;
RedisModuleEvent event;
RedisModuleEvent event;
...
@@ -5743,10 +5726,12 @@ int RedisModule_SubscribeToServerEvent(RedisModuleCtx *ctx, RedisModuleEvent eve
...
@@ -5743,10 +5726,12 @@ int RedisModule_SubscribeToServerEvent(RedisModuleCtx *ctx, RedisModuleEvent eve
/* Modify or remove the event listener if we already had one. */
/* Modify or remove the event listener if we already had one. */
if (ln) {
if (ln) {
if (callback == NULL)
if (callback == NULL)
{
listDelNode(RedisModule_EventListeners,ln);
listDelNode(RedisModule_EventListeners,ln);
else
zfree(el);
} else {
el->callback = callback; /* Update the callback with the new one. */
el->callback = callback; /* Update the callback with the new one. */
}
return REDISMODULE_OK;
return REDISMODULE_OK;
}
}
...
@@ -5767,6 +5752,11 @@ int RedisModule_SubscribeToServerEvent(RedisModuleCtx *ctx, RedisModuleEvent eve
...
@@ -5767,6 +5752,11 @@ int RedisModule_SubscribeToServerEvent(RedisModuleCtx *ctx, RedisModuleEvent eve
* 'eid' and 'subid' are just the main event ID and the sub event associated
* 'eid' and 'subid' are just the main event ID and the sub event associated
* with the event, depending on what exactly happened. */
* with the event, depending on what exactly happened. */
void RedisModule_FireServerEvent(uint64_t eid, int subid, void *data) {
void RedisModule_FireServerEvent(uint64_t eid, int subid, void *data) {
/* Fast path to return ASAP if there is nothing to do, avoiding to
* setup the iterator and so forth: we want this call to be extremely
* cheap if there are no registered modules. */
if (listLength(RedisModule_EventListeners) == 0) return;
listIter li;
listIter li;
listNode *ln;
listNode *ln;
listRewind(RedisModule_EventListeners,&li);
listRewind(RedisModule_EventListeners,&li);
...
@@ -5779,9 +5769,7 @@ void RedisModule_FireServerEvent(uint64_t eid, int subid, void *data) {
...
@@ -5779,9 +5769,7 @@ void RedisModule_FireServerEvent(uint64_t eid, int subid, void *data) {
void *moduledata = NULL;
void *moduledata = NULL;
struct moduleClientInfoV1 civ1;
struct moduleClientInfoV1 civ1;
if (eid == REDISMODULE_EVENT_ID_CLIENT_CONNNECTED ||
if (eid == REDISMODULE_EVENT_ID_CLIENT_CHANGE) {
eid == REDISMODULE_EVENT_ID_CLIENT_DISCONNECTED)
{
modulePopulateClientInfoStructure(&civ1,data,
modulePopulateClientInfoStructure(&civ1,data,
el->event.dataver);
el->event.dataver);
}
}
...
...
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