[FFmpeg-devel] [PATCH 1/2] avfilter/all: propagate errors of functions from avfilter/formats

Michael Niedermayer michael at niedermayer.cc
Tue Oct 6 17:44:48 CEST 2015


On Tue, Oct 06, 2015 at 04:40:36PM +0200, Nicolas George wrote:
> Le quartidi 14 vendémiaire, an CCXXIV, Ganesh Ajjanagadde a écrit :
> > -    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
> > +    if (!layouts)
> > +        return AVERROR(ENOMEM);
> > +    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0) {
> > +        ff_channel_layouts_unref(&layouts);
> > +        return ret;
> 
> This is a pattern that comes frequently, there is probably room for code
> factorization.
> 
> How about this: currently, ff_formats_ref() and cousins reject NULL with
> AVERROR_BUG. If it is changed to return AVERROR(ENOMEM) instead, then all
> the "if (!formats) return AVERROR(ENOMEM);" become unnecessary.
> 
> Second, if ff_formats_ref() is changed to unref the format list on failure,
> then all the unref become unnecessary. The changed code would be just:
> 
>      layouts = ff_all_channel_counts();
> -    ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
> +    if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
> +        return ret;
> 
> That is rather less cluttered.

+1

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151006/2d1d9028/attachment.sig>


More information about the ffmpeg-devel mailing list