summaryrefslogtreecommitdiff
path: root/main/core_unreal.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2013-12-18 19:28:05 +0000
committerJoshua Colp <jcolp@digium.com>2013-12-18 19:28:05 +0000
commite2630fcd516b8f794bf342d9fd267b0c905e79ce (patch)
treef6cd5cf70eb9af24b239d78391aed7472c09dd7f /main/core_unreal.c
parente23b8d19a49d4ee4faf3dc167ddb7ba7afe36a46 (diff)
channels: Return allocated channels locked.
This change makes ast_channel_alloc return allocated channels locked. By doing so no other thread can acquire, lock, and manipulate the channel before it is completely set up. (closes issue AST-1256) Review: https://reviewboard.asterisk.org/r/3067/ ........ Merged revisions 404204 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404210 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/core_unreal.c')
-rw-r--r--main/core_unreal.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/main/core_unreal.c b/main/core_unreal.c
index 7e457f484..7ab7da765 100644
--- a/main/core_unreal.c
+++ b/main/core_unreal.c
@@ -906,57 +906,72 @@ struct ast_channel *ast_unreal_new_channels(struct ast_unreal_pvt *p,
*/
if (!(owner = ast_channel_alloc(1, semi1_state, NULL, NULL, NULL,
exten, context, linkedid, 0,
- "%s/%s-%08x;1", tech->type, p->name, generated_seqno))
- || !(chan = ast_channel_alloc(1, semi2_state, NULL, NULL, NULL,
- exten, context, ast_channel_linkedid(owner), 0,
- "%s/%s-%08x;2", tech->type, p->name, generated_seqno))) {
- if (owner) {
- owner = ast_channel_release(owner);
- }
- ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
+ "%s/%s-%08x;1", tech->type, p->name, generated_seqno))) {
+ ast_log(LOG_WARNING, "Unable to allocate owner channel structure\n");
return NULL;
}
if (callid) {
ast_channel_callid_set(owner, callid);
- ast_channel_callid_set(chan, callid);
}
ast_channel_tech_set(owner, tech);
- ast_channel_tech_set(chan, tech);
+ ao2_ref(p, +1);
ast_channel_tech_pvt_set(owner, p);
- ast_channel_tech_pvt_set(chan, p);
ast_format_cap_copy(ast_channel_nativeformats(owner), p->reqcap);
- ast_format_cap_copy(ast_channel_nativeformats(chan), p->reqcap);
/* Determine our read/write format and set it on each channel */
ast_best_codec(p->reqcap, &fmt);
ast_format_copy(ast_channel_writeformat(owner), &fmt);
- ast_format_copy(ast_channel_writeformat(chan), &fmt);
ast_format_copy(ast_channel_rawwriteformat(owner), &fmt);
- ast_format_copy(ast_channel_rawwriteformat(chan), &fmt);
ast_format_copy(ast_channel_readformat(owner), &fmt);
- ast_format_copy(ast_channel_readformat(chan), &fmt);
ast_format_copy(ast_channel_rawreadformat(owner), &fmt);
- ast_format_copy(ast_channel_rawreadformat(chan), &fmt);
ast_set_flag(ast_channel_flags(owner), AST_FLAG_DISABLE_DEVSTATE_CACHE);
- ast_set_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
ast_jb_configure(owner, &p->jb_conf);
if (ast_channel_cc_params_init(owner, requestor
? ast_channel_get_cc_config_params((struct ast_channel *) requestor) : NULL)) {
+ ao2_ref(p, -1);
+ ast_channel_unlock(owner);
ast_channel_release(owner);
- ast_channel_release(chan);
return NULL;
}
- /* Give the private a ref for each channel. */
- ao2_ref(p, +2);
p->owner = owner;
+ ast_channel_unlock(owner);
+
+ if (!(chan = ast_channel_alloc(1, semi2_state, NULL, NULL, NULL,
+ exten, context, ast_channel_linkedid(owner), 0,
+ "%s/%s-%08x;2", tech->type, p->name, generated_seqno))) {
+ ast_log(LOG_WARNING, "Unable to allocate chan channel structure\n");
+ ao2_ref(p, -1);
+ ast_channel_release(owner);
+ return NULL;
+ }
+
+ if (callid) {
+ ast_channel_callid_set(chan, callid);
+ }
+
+ ast_channel_tech_set(chan, tech);
+ ao2_ref(p, +1);
+ ast_channel_tech_pvt_set(chan, p);
+
+ ast_format_cap_copy(ast_channel_nativeformats(chan), p->reqcap);
+
+ /* Format was already determined when setting up owner */
+ ast_format_copy(ast_channel_writeformat(chan), &fmt);
+ ast_format_copy(ast_channel_rawwriteformat(chan), &fmt);
+ ast_format_copy(ast_channel_readformat(chan), &fmt);
+ ast_format_copy(ast_channel_rawreadformat(chan), &fmt);
+
+ ast_set_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_DEVSTATE_CACHE);
+
p->chan = chan;
+ ast_channel_unlock(chan);
return owner;
}