[Asterisk-Dev] what can i do on an unlocked ast_channel ?

Luigi Rizzo rizzo at icir.org
Sat May 14 07:30:25 MST 2005


I was wondering what is the locking scheme used for struct ast_channel.
I cannot find anything in the source (channel.h, channel.c) except
figuring out (from the code) that:

 - chlock protects the two lists 'channels' and 'backends'.
   So if I hold chlock, nobody else should free() any of the objects
   on the 'channels' list (not sure about 'backends' though
   maybe there is no contention on those objects by separate threads.

 - c->lock "lock a channel for some operations" (from channel.h)

I have no idea of the meaning of the latter.
But looking at ast_channel_free() it seems that
there is a risk that a struct ast_channel can get freed if
noone holds that mutex.

The question arises because there is some code in e.g.
apps/app_chanspy.c::local_channel_walk() that returns a
pointer to an unlocked channel, and then dereferences it
without apparently holding any lock. How do we guarantee
that this does not result in dereferencing an invalid pointer ?
Perhaps because it is guaranteed that such ops and
the call to ast_channel_free() cannot occur in different
threads ?

	cheers
	luigi



More information about the asterisk-dev mailing list