res_stasis.c: Protect channel datastore list from stasis end.
authorRichard Mudgett <rmudgett@digium.com>
Wed, 30 Mar 2016 18:31:44 +0000 (13:31 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Wed, 30 Mar 2016 21:33:56 +0000 (16:33 -0500)
Change-Id: Ifadc469590bd4d5368e19d3763db3bd1f80fdb95

res/res_stasis.c

index 63c565d..b26cfdd 100644 (file)
@@ -1188,10 +1188,11 @@ void stasis_app_channel_set_stasis_end_published(struct ast_channel *chan)
        struct ast_datastore *datastore;
 
        datastore = ast_datastore_alloc(&set_end_published_info, NULL);
-
-       ast_channel_lock(chan);
-       ast_channel_datastore_add(chan, datastore);
-       ast_channel_unlock(chan);
+       if (datastore) {
+               ast_channel_lock(chan);
+               ast_channel_datastore_add(chan, datastore);
+               ast_channel_unlock(chan);
+       }
 }
 
 int stasis_app_channel_is_stasis_end_published(struct ast_channel *chan)
@@ -1211,12 +1212,11 @@ static void remove_stasis_end_published(struct ast_channel *chan)
 
        ast_channel_lock(chan);
        datastore = ast_channel_datastore_find(chan, &set_end_published_info, NULL);
-       ast_channel_unlock(chan);
-
        if (datastore) {
                ast_channel_datastore_remove(chan, datastore);
                ast_datastore_free(datastore);
        }
+       ast_channel_unlock(chan);
 }
 
 /*! /brief Stasis dialplan application callback */