[FFmpeg-devel] [PATCH] Avoid pointless check before calling free

Clément Bœsch ubitux
Thu Feb 3 02:49:23 CET 2011

On Thu, Feb 03, 2011 at 01:43:04AM +0000, M?ns Rullg?rd wrote:
> Cl?ment B?sch <ubitux at gmail.com> writes:
> > Hi,
> >
> > We recently tracked down and annihilated most of (all?) the if (p) free(p) in
> > MPlayer, and I thought it could be a good idea to do the same with FFmpeg. So
> > here is two patches:
> >
> > - the first one in order to delete a pointless free made on each av_free call,
> You obviously meant "pointless if()" ...

Oups yes, sorry it's late here.

> > - the second to remove the few remaining if (p) av_free(p) I was able to find.
> Thanks for taking the time to do this.  Both patches queued.

Oh. That was quick, thanks.

> > Note that I didn't touch the av_freep ones since I'm not sure of the real
> > benefit.
> Did you find similar pointless checks related to av_freep, or what do
> you mean?
> The purpose of av_freep() is to free the buffer and set the pointer to
> NULL as an extra precaution against accessing freed memory and double
> frees.

Yes, there is a few if (p) av_freep(&p) but I did not make the changes
since a I thought assigning to NULL a pointer already NULL may not be
justified. I can provide another patch tomorrow for those if you wish, but
as I meant to say, I'm not sure it's worth the change.

Cl?ment B.

More information about the ffmpeg-devel mailing list