From d3eb0028e937fe8c6b435bcb3760f676dcc0920f Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 20 Dec 2018 17:40:55 +0100 Subject: [PATCH] Modules shared API: also unregister the module as user. --- src/module.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/module.c b/src/module.c index 4f0e5b126..7bb146954 100644 --- a/src/module.c +++ b/src/module.c @@ -4723,6 +4723,27 @@ int moduleUnregisterSharedAPI(RedisModule *module) { return count; } +/* Remove the specified module as an user of APIs of ever other module. + * This is usually called when a module is unloaded. + * + * Returns the number of modules this module was using APIs from. */ +int moduleUnregisterUsedAPI(RedisModule *module) { + listIter li; + listNode *ln; + int count = 0; + + listRewind(module->using,&li); + while((ln = listNext(&li))) { + RedisModule *used = ln->value; + listNode *ln = listSearchKey(used->usedby,module); + if (ln) { + listDelNode(module->using,ln); + count++; + } + } + return count; +} + /* -------------------------------------------------------------------------- * Modules API internals * -------------------------------------------------------------------------- */ @@ -4867,6 +4888,7 @@ int moduleLoad(const char *path, void **module_argv, int module_argc) { if (ctx.module) { moduleUnregisterCommands(ctx.module); moduleUnregisterSharedAPI(ctx.module); + moduleUnregisterUsedAPI(ctx.module); moduleFreeModuleStructure(ctx.module); } dlclose(handle); @@ -4906,6 +4928,7 @@ int moduleUnload(sds name) { moduleUnregisterCommands(module); moduleUnregisterSharedAPI(module); + moduleUnregisterUsedAPI(module); /* Remove any notification subscribers this module might have */ moduleUnsubscribeNotifications(module);