diff options
author | Corey Farrell <git@cfware.com> | 2017-12-29 19:24:02 -0500 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2018-01-03 17:23:36 -0500 |
commit | 55f1d69c43d2c6c87eec50fd3eed7a77ba2e912b (patch) | |
tree | 0749060ca9d29dc796152f1654a340f091f4f600 /main/sorcery.c | |
parent | 7f4facc5e4a96ccae10283da998044becc4fbe11 (diff) |
loader: Create ast_module_running_ref.
This function returns NULL if the module in question is not running. I
did not change ast_module_ref as most callers do not check the result
and they always call ast_module_unref.
Make use of this function when running registered items from:
* app_stack API's
* bridge technologies
* CLI commands
* File formats
* Manager Actions
* RTP engines
* Sorcery Wizards
* Timing Interfaces
* Translators
* AGI Commands
* Fax Technologies
ASTERISK-20346 #close
Change-Id: Ia16fd28e188b2fc0b9d18b8a5d9cacc31df73fcc
Diffstat (limited to 'main/sorcery.c')
-rw-r--r-- | main/sorcery.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/main/sorcery.c b/main/sorcery.c index a55d5c72e..c79675cd8 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -835,16 +835,19 @@ enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sor RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, ao2_alloc(sizeof(*object_wizard), sorcery_object_wizard_destructor), ao2_cleanup); int created = 0; - if (!wizard) { + if (!object_wizard) { + return AST_SORCERY_APPLY_FAIL; + } + + if (!wizard || wizard->callbacks.module != ast_module_running_ref(wizard->callbacks.module)) { ast_log(LOG_ERROR, "Wizard '%s' could not be applied to object type '%s' as it was not found\n", name, type); return AST_SORCERY_APPLY_FAIL; - } else if (!object_wizard) { - return AST_SORCERY_APPLY_FAIL; } if (!object_type) { if (!(object_type = sorcery_object_type_alloc(type, module))) { + ast_module_unref(wizard->callbacks.module); return AST_SORCERY_APPLY_FAIL; } created = 1; @@ -861,6 +864,7 @@ enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sor ast_debug(1, "Wizard %s already applied to object type %s\n", wizard->callbacks.name, object_type->name); AST_VECTOR_RW_UNLOCK(&object_type->wizards); + ast_module_unref(wizard->callbacks.module); return AST_SORCERY_APPLY_DUPLICATE; } } @@ -871,11 +875,10 @@ enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sor ast_log(LOG_WARNING, "Wizard '%s' failed to open mapping for object type '%s' with data: %s\n", name, object_type->name, S_OR(data, "")); AST_VECTOR_RW_UNLOCK(&object_type->wizards); + ast_module_unref(wizard->callbacks.module); return AST_SORCERY_APPLY_FAIL; } - ast_module_ref(wizard->callbacks.module); - object_wizard->wizard = ao2_bump(wizard); object_wizard->caching = caching; |