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

Nicolas George george at nsup.org
Tue Oct 6 16:40:36 CEST 2015


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.

What do you think about this?

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151006/4425959a/attachment.sig>


More information about the ffmpeg-devel mailing list