[asterisk-dev] ast_frame allocation/free question
Sergio Garcia Murillo
sergio.garcia at fontventa.com
Wed Nov 28 07:28:44 CST 2007
From: Kevin P. Fleming [mailto:kpfleming at digium.com]
>> 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
> c 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).
And that's exactly the source of all the misundestanding, if there's a
member of the structure to record which parts of the frame I have allocated
and I see that ast_frame_free frees the frame based on that, it's a logical
step to think that if I correctly set the value someone is going to free the
frames for me. I mean, I don't need to check the mallocd of a frame to
know what do I have allocated a few lines before.. :)
Best regards
Sergio
More information about the asterisk-dev
mailing list