[asterisk-dev] ast_frame allocation/free question

Kevin P. Fleming kpfleming at digium.com
Wed Nov 28 06:45:45 CST 2007

Simon Perreault wrote:

> In my case, it was simply because of the existence of the mallocd member. I 
> still don't understand what its role is. In both cases #1 and #2, it doesn't 
> matter what value I set it to since the channel won't care. This didn't seem 
> to make sense, so that's why I assumed that the channel would use the mallocd 
> member and free the frame itself.

Have you looked at the code for ast_frame_free()? The reason those
members are there (which is documented in frame.h) is so that
ast_frame_free() can know which parts (if any) of the frame were
dynamically allocated and which parts were not. For example, it is
common to have a non-dynamically-allocated frame header (on the stack or
static) with dynamically allocated payload. The creator of the ast_frame
object will make those decisions, and none of the users of the frame
(*including* the new owner of the frame) need to care about them at all,
because only ast_frame_free() will react to them. (Technically that is
not true, as there are ways to duplicate frames as well, and those
structure members will be taken into account during the copy process,
and the copied frame will have a different set of flags even though it
has the same contents).

Kevin P. Fleming
Director of Software Technologies
Digium, Inc. - "The Genuine Asterisk Experience" (TM)

More information about the asterisk-dev mailing list