[asterisk-dev] Is this locking sequence correct?

Kirill Katsnelson kkm at adaptiveai.com
Thu Feb 3 02:53:41 CST 2011

I am probably missing something about locking. Here is a trimmed down 
piece of code from chan_sip.c:

if (p->owner) {
   struct ast_channel *owner = p->owner;
     /* ... Do something interesting here ...  */
     /* Oops, or not? */

My question is about the 2 last calls. After ast_channel_unref(), the 
channel is neither locked nor referenced. Can the channel then just go 
away such that sip_pvt_lock() might be too late to call already? Is it 
more correct to call sip_pvt_lock() before ast_channel_unref(), or am I 
just misunderstanding the semantics? Is it guaranteed here that 
ast_channel_unref() does not unref the last reference?


More information about the asterisk-dev mailing list