[asterisk-dev] ast_frame allocation/free question

Matthew Nicholson mnicholson at digium.com
Tue Nov 27 17:03:11 CST 2007


On Tue, 2007-11-27 at 21:06 +0100, Sergio Garcia Murillo wrote:
> From: "Kevin P. Fleming" <kpfleming at digium.com>
> > Sergio Garcia Murillo wrote:
> >
> > > So if you're writting a custom application you have to take care for
> > > deleting the
> > > frames you write and the frames you read, but if you write a custom
> channel
> > > you
> > > don't have to worry?
> > > Shouldn't be better to have a general policy about it, for example the
> one
> > > that creates
> > > the frame has to take care of deleting it, or the one that consumes the
> > > frame is the one
> > > that  deletes it. Just as an idea, as I said before I've just made
> > > everything static and
> > > fixed my problem.
> >
> > So what is your definition of 'consume'? The application you are writing
> > is the one that is 'consuming' the frames. If ast_write() was the
> > consumer, then you'd never be able to write the frame to more than one
> > location without duplicating it, which would be needless overhead.
> >
> 
> I agree, but I think that it's a usually a good practice that the one that
> allocates
> the memory is the reponsible of freeing it. What I don't really see is why
> the
> apps need to call the ast_frfree on frames they have just readen.
> Also as Russell pointed I perhaps should be using the ast_frame_header_new()
> if i really need to dinamically allocate frames.


We don't need a set of general rules like "if you alloc,  you should
free" (if frames were reference counted, this might make sense).  We
need a set of rules like "you are responsible for freeing frames
returned from ast_read()" or "ast_write() does not automatically free
written frames, you are still responsible".  Clearly documenting who is
responsible for cleaning up resources should clear up the confusion
here.

-- 
Matthew Nicholson
Digium




More information about the asterisk-dev mailing list