<div dir="ltr"><p dir="ltr">If it's possible for apps_registry to be NULL then it's possible for the condition to race. Maybe we need to use AO2_GLOBAL_OBJ_STATIC? Could this issue apply to the other global containers in this module (app_controls, app_bridges, app_bridges_moh, app_bridges_playback)?<br></p>
<div class="gmail_quote">---------- Forwarded message ----------<br>From: "SVN commits to the Asterisk project" <<a href="mailto:asterisk-commits@lists.digium.com" target="_blank">asterisk-commits@lists.digium.com</a>><br>Date: Nov 1, 2014 9:01 PM<br>Subject: [asterisk-commits] mjordan: branch 12 r426995 - /branches/12/res/res_stasis.c<br>To: <<a href="mailto:asterisk-commits@lists.digium.com" target="_blank">asterisk-commits@lists.digium.com</a>>, <<a href="mailto:svn-commits@lists.digium.com" target="_blank">svn-commits@lists.digium.com</a>><br>Cc: <br><br type="attribution">Author: mjordan<br>
Date: Sat Nov 1 20:01:15 2014<br>
New Revision: 426995<br>
<br>
URL: <a href="http://svnview.digium.com/svn/asterisk?view=rev&rev=426995" target="_blank">http://svnview.digium.com/svn/asterisk?view=rev&rev=426995</a><br>
Log:<br>
res/res_stasis: Fix crash on module unload while performing operation<br>
<br>
When the res_stasis module is unloaded, it will dispose of the apps_registry<br>
container. This is a problem if an ARI operation is in flight that attempts<br>
to use the registry, as the shutdown occurs in a separate thread. This patch<br>
adds some sanity checks to the various routines that access the registry which<br>
cause the operations to fail if the apps_registry does not exist.<br>
<br>
Crash caught by the Asterisk Test Suite.<br>
<br>
Modified:<br>
branches/12/res/res_stasis.c<br>
<br>
Modified: branches/12/res/res_stasis.c<br>
URL: <a href="http://svnview.digium.com/svn/asterisk/branches/12/res/res_stasis.c?view=diff&rev=426995&r1=426994&r2=426995" target="_blank">http://svnview.digium.com/svn/asterisk/branches/12/res/res_stasis.c?view=diff&rev=426995&r1=426994&r2=426995</a><br>
==============================================================================<br>
--- branches/12/res/res_stasis.c (original)<br>
+++ branches/12/res/res_stasis.c Sat Nov 1 20:01:15 2014<br>
@@ -1204,6 +1204,10 @@<br>
*/<br>
remove_stasis_end_published(chan);<br>
<br>
+ if (!apps_registry) {<br>
+ return -1;<br>
+ }<br>
+<br>
app = ao2_find(apps_registry, app_name, OBJ_SEARCH_KEY);<br>
if (!app) {<br>
ast_log(LOG_ERROR,<br>
@@ -1364,6 +1368,10 @@<br>
{<br>
RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);<br>
<br>
+ if (!apps_registry) {<br>
+ return -1;<br>
+ }<br>
+<br>
app = ao2_find(apps_registry, app_name, OBJ_SEARCH_KEY);<br>
if (!app) {<br>
/* XXX We can do a better job handling late binding, queueing up<br>
@@ -1381,6 +1389,10 @@<br>
{<br>
struct stasis_app *res = NULL;<br>
<br>
+ if (!apps_registry) {<br>
+ return NULL;<br>
+ }<br>
+<br>
if (!ast_strlen_zero(app_name)) {<br>
res = ao2_find(apps_registry, app_name, OBJ_SEARCH_KEY);<br>
}<br>
@@ -1405,6 +1417,10 @@<br>
{<br>
RAII_VAR(struct ao2_container *, apps, NULL, ao2_cleanup);<br>
<br>
+ if (!apps_registry) {<br>
+ return NULL;<br>
+ }<br>
+<br>
apps = ast_str_container_alloc(1);<br>
if (!apps) {<br>
return NULL;<br>
@@ -1419,8 +1435,11 @@<br>
{<br>
RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);<br>
<br>
- SCOPED_LOCK(apps_lock, apps_registry, ao2_lock, ao2_unlock);<br>
-<br>
+ if (!apps_registry) {<br>
+ return -1;<br>
+ }<br>
+<br>
+ ao2_lock(apps_registry);<br>
app = ao2_find(apps_registry, app_name, OBJ_SEARCH_KEY | OBJ_NOLOCK);<br>
if (app) {<br>
app_update(app, handler, data);<br>
@@ -1429,6 +1448,7 @@<br>
if (app) {<br>
ao2_link_flags(apps_registry, app, OBJ_NOLOCK);<br>
} else {<br>
+ ao2_unlock(apps_registry);<br>
return -1;<br>
}<br>
}<br>
@@ -1437,6 +1457,7 @@<br>
* prevent memory leaks, and we're lazy.<br>
*/<br>
cleanup();<br>
+ ao2_unlock(apps_registry);<br>
return 0;<br>
}<br>
<br>
@@ -1445,6 +1466,10 @@<br>
RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);<br>
<br>
if (!app_name) {<br>
+ return;<br>
+ }<br>
+<br>
+ if (!apps_registry) {<br>
return;<br>
}<br>
<br>
@@ -1837,6 +1862,7 @@<br>
<br>
messaging_cleanup();<br>
<br>
+ cleanup();<br>
ao2_cleanup(apps_registry);<br>
apps_registry = NULL;<br>
<br>
<br>
<br>
--<br>
_____________________________________________________________________<br>
-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
<br>
asterisk-commits mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
<a href="http://lists.digium.com/mailman/listinfo/asterisk-commits" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-commits</a><br>
</div>
</div>