Modules shared API: also unregister the module as user.

This commit is contained in:
antirez 2018-12-20 17:40:55 +01:00
parent 9403b3d7a3
commit d3eb0028e9

View File

@ -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);