[FFmpeg-devel] [PATCH 3/4] dict.c: Free non-strduped av_dict_set arguments on error.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat Aug 16 14:36:56 CEST 2014

On Mon, Aug 11, 2014 at 10:11:59PM +0200, wm4 wrote:
> On Mon, 11 Aug 2014 21:17:18 +0200
> Reimar Döffinger <Reimar.Doeffinger at gmx.de> wrote:
> > Unfortunately this was not explicitly documented and thus
> > might be very risky.
> > But basically all uses I saw in FFmpeg had a memleak in these
> > cases.
> It's the more convenient behavior, although on the other hand it feels
> wrong to change the input data on error.
> This makes me wonder, isn't AV_DICT_DONT_STRDUP_* too obscure and too
> much of a microoptimization, that we have to risk retro-guessing these
> subtle semantics?

That is kind of the point: With the behaviour I propose, it is actually
really convenient to use.
Because it means you can just push av_asprintf into it and forget about
If we instead just removed AV_DICT_DONT_STRDUP_* you end up with having
to put it in a variable and then free it afterwards.
Which is what I have seen some code do (the only code that does not have
a memleak), and it's rather a lot of clutter.

More information about the ffmpeg-devel mailing list