summaryrefslogtreecommitdiff
path: root/main/channel.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2013-12-18 20:33:37 +0000
committerKevin Harwell <kharwell@digium.com>2013-12-18 20:33:37 +0000
commit28c0cb28d0815e5e59ab99b60ac6b50e1ed9cbae (patch)
treeb42967f4899ba28aea79b9a11827c814b95b62c8 /main/channel.c
parent86b5e11607e2e3b7dcfb0b72d41b492ce868f31c (diff)
channel locking: Add locking for channel snapshot creation
Original commit message by mmichelson (asterisk 12 r403311): "This adds channel locks around calls to create channel snapshots as well as other functions which operate on a channel and then end up creating a channel snapshot. Functions that expect the channel to be locked prior to being called have had their documentation updated to indicate such." The above was initially committed and then reverted at r403398. The problem was found to be in core_local.c in the publish_local_bridge_message function. The ast_unreal_lock_all function locks and adds a reference to the returned channels and while they were being unlocked they were not being unreffed when no longer needed. Fixed by unreffing the channels. Also in bridge.c a lock was obtained on "other->chan", but then an attempt was made to unlock "other" and not the previously locked channel. Fixed by unlocking "other->chan" (closes issue ASTERISK-22709) Reported by: John Bigelow ........ Merged revisions 404237 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404260 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/channel.c')
-rw-r--r--main/channel.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/main/channel.c b/main/channel.c
index 418e6a772..669b81529 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -678,7 +678,9 @@ int ast_str2cause(const char *name)
static struct stasis_message *create_channel_snapshot_message(struct ast_channel *channel)
{
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+ ast_channel_lock(channel);
snapshot = ast_channel_snapshot_create(channel);
+ ast_channel_unlock(channel);
if (!snapshot) {
return NULL;
}
@@ -1267,6 +1269,7 @@ int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HOLD };
int res;
+ ast_channel_lock(chan);
if (!ast_strlen_zero(musicclass)) {
f.data.ptr = (void *) musicclass;
f.datalen = strlen(musicclass) + 1;
@@ -1278,6 +1281,7 @@ int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
ast_channel_publish_blob(chan, ast_channel_hold_type(), blob);
res = ast_queue_frame(chan, &f);
+ ast_channel_unlock(chan);
return res;
}
@@ -1286,9 +1290,11 @@ int ast_queue_unhold(struct ast_channel *chan)
struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_UNHOLD };
int res;
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, ast_channel_unhold_type(), NULL);
res = ast_queue_frame(chan, &f);
+ ast_channel_unlock(chan);
return res;
}
@@ -2254,7 +2260,9 @@ static void ast_channel_destructor(void *obj)
/* Things that may possibly raise Stasis messages shouldn't occur after this point */
ast_set_flag(ast_channel_flags(chan), AST_FLAG_DEAD);
+ ast_channel_lock(chan);
ast_channel_publish_snapshot(chan);
+ ast_channel_unlock(chan);
publish_cache_clear(chan);
ast_channel_lock(chan);
@@ -5324,7 +5332,9 @@ static int set_format(struct ast_channel *chan,
generator_write_format_change(chan);
}
+ ast_channel_lock(chan);
ast_channel_publish_snapshot(chan);
+ ast_channel_unlock(chan);
return 0;
}
@@ -5405,7 +5415,9 @@ static int set_format(struct ast_channel *chan,
generator_write_format_change(chan);
}
+ ast_channel_lock(chan);
ast_channel_publish_snapshot(chan);
+ ast_channel_unlock(chan);
return res;
}
@@ -5622,7 +5634,9 @@ struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_chan
/* Copy/inherit important information into new channel */
if (oh) {
if (oh->vars) {
+ ast_channel_lock(new_chan);
ast_set_variables(new_chan, oh->vars);
+ ast_channel_unlock(new_chan);
}
if (oh->parent_channel) {
call_forward_inherit(new_chan, oh->parent_channel, orig);
@@ -5683,7 +5697,9 @@ struct ast_channel *__ast_request_and_dial(const char *type, struct ast_format_c
if (oh) {
if (oh->vars) {
+ ast_channel_lock(chan);
ast_set_variables(chan, oh->vars);
+ ast_channel_unlock(chan);
}
if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
/*
@@ -5955,7 +5971,9 @@ struct ast_channel *ast_request(const char *type, struct ast_format_cap *request
if (requestor) {
struct ast_callid *callid = ast_channel_callid(requestor);
if (callid) {
+ ast_channel_lock(c);
ast_channel_callid_set(c, callid);
+ ast_channel_unlock(c);
callid = ast_callid_unref(callid);
}
}