diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c index cfc6d16f5d78a8889649b44d151c65daa1078403..15ff8fa456abde3c29c85dee9289e60762ce26c0 100644 --- a/res/res_http_websocket.c +++ b/res/res_http_websocket.c @@ -122,6 +122,10 @@ int AST_OPTIONAL_API_NAME(ast_websocket_add_protocol)(const char *name, ast_webs { struct websocket_protocol *protocol; + if (!protocols) { + return -1; + } + ao2_lock(protocols); /* Ensure a second protocol handler is not registered for the same protocol */ @@ -157,6 +161,10 @@ int AST_OPTIONAL_API_NAME(ast_websocket_remove_protocol)(const char *name, ast_w { struct websocket_protocol *protocol; + if (!protocols) { + return -1; + } + if (!(protocol = ao2_find(protocols, name, OBJ_KEY))) { return -1; } @@ -670,6 +678,7 @@ static int unload_module(void) ast_websocket_remove_protocol("echo", websocket_echo_callback); ast_http_uri_unlink(&websocketuri); ao2_ref(protocols, -1); + protocols = NULL; return 0; } diff --git a/res/res_stasis_websocket.c b/res/res_stasis_websocket.c index b4819aec991ea6a61bd3a9de2b4ba1f3645f9f84..bfaeea07ce82f5cd09286f13780dc7a165654fb8 100644 --- a/res/res_stasis_websocket.c +++ b/res/res_stasis_websocket.c @@ -305,7 +305,7 @@ static int load_module(void) /* ironic */ return AST_MODULE_LOAD_FAILURE; } - r |= ast_websocket_add_protocol(ws_protocol, websocket_callback); + r |= ast_websocket_add_protocol(ws_protocol, websocket_callback); return r; } @@ -315,12 +315,13 @@ static int unload_module(void) ast_json_unref(oom_json); oom_json = NULL; - r |= ast_websocket_remove_protocol(ws_protocol, websocket_callback); + r |= ast_websocket_remove_protocol(ws_protocol, websocket_callback); return r; } AST_MODULE_INFO(ASTERISK_GPL_KEY, 0, "Stasis HTTP bindings", .load = load_module, .unload = unload_module, - .nonoptreq = "app_stasis,res_http_websocket" + .nonoptreq = "app_stasis,res_http_websocket", + .load_pri = AST_MODPRI_APP_DEPEND, );