libavfilter/vf_scale.c:130: error: Use After Free
  call to `ff_formats_unref()` eventually accesses memory that was invalidated by call to `free()` on line 129 indirectly during the call to `ff_add_format()`.

libavfilter/vf_scale.c:124:9: invalidation part of the trace starts here
122.     if (ctx->inputs[0]) {
123.         const AVPixFmtDescriptor *desc = NULL;
124.         formats = NULL;
             ^
125.         while ((desc = av_pix_fmt_desc_next(desc))) {
126.             pix_fmt = av_pix_fmt_desc_get_id(desc);

libavfilter/vf_scale.c:124:9: variable `formats` accessed here
  122.     if (ctx->inputs[0]) {
  123.         const AVPixFmtDescriptor *desc = NULL;
  124.         formats = NULL;
               ^
  125.         while ((desc = av_pix_fmt_desc_next(desc))) {
  126.             pix_fmt = av_pix_fmt_desc_get_id(desc);

libavfilter/vf_scale.c:129:27: when calling `ff_add_format` here
  127.             if ((sws_isSupportedInput(pix_fmt) ||
  128.                  sws_isSupportedEndiannessConversion(pix_fmt))
  129.                 && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
                                 ^
  130.                 ff_formats_unref(&formats);
  131.                 return ret;

libavfilter/formats.c:201:1: parameter `avff` of ff_add_format
    199. } while (0)
    200. 
    201. int ff_add_format(AVFilterFormats **avff, int fmt)
         ^
    202. {
    203.     ADD_FORMAT(avff, fmt, int, formats, nb_formats);

libavfilter/formats.c:203:5: when calling `av_freep` here
    201. int ff_add_format(AVFilterFormats **avff, int fmt)
    202. {
    203.     ADD_FORMAT(avff, fmt, int, formats, nb_formats);
             ^
    204. }
    205. 

libavutil/mem.c:198:1: parameter `arg` of av_freep
      196. }
      197. 
      198. void av_freep(void *arg)
           ^
      199. {
      200.     void **ptr = (void **)arg;

libavutil/mem.c:200:5: assigned
      198. void av_freep(void *arg)
      199. {
      200.     void **ptr = (void **)arg;
               ^
      201.     av_free(*ptr);
      202.     *ptr = NULL;

libavutil/mem.c:201:5: when calling `av_free` here
      199. {
      200.     void **ptr = (void **)arg;
      201.     av_free(*ptr);
               ^
      202.     *ptr = NULL;
      203. }

libavutil/mem.c:186:1: parameter `ptr` of av_free
        184. }
        185. 
        186. void av_free(void *ptr)
             ^
        187. {
        188. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:194:5: was invalidated by call to `free()`
        192.     _aligned_free(ptr);
        193. #else
        194.     free(ptr);
                 ^
        195. #endif
        196. }

libavfilter/vf_scale.c:124:9: use-after-lifetime part of the trace starts here
122.     if (ctx->inputs[0]) {
123.         const AVPixFmtDescriptor *desc = NULL;
124.         formats = NULL;
             ^
125.         while ((desc = av_pix_fmt_desc_next(desc))) {
126.             pix_fmt = av_pix_fmt_desc_get_id(desc);

libavfilter/vf_scale.c:124:9: variable `formats` accessed here
  122.     if (ctx->inputs[0]) {
  123.         const AVPixFmtDescriptor *desc = NULL;
  124.         formats = NULL;
               ^
  125.         while ((desc = av_pix_fmt_desc_next(desc))) {
  126.             pix_fmt = av_pix_fmt_desc_get_id(desc);

libavfilter/vf_scale.c:130:17: when calling `ff_formats_unref` here
  128.                  sws_isSupportedEndiannessConversion(pix_fmt))
  129.                 && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
  130.                 ff_formats_unref(&formats);
                       ^
  131.                 return ret;
  132.             }

libavfilter/formats.c:304:1: parameter `ref` of ff_formats_unref
    302. } while (0)
    303. 
    304. void ff_formats_unref(AVFilterFormats **ref)
         ^
    305. {
    306.     FORMATS_UNREF(ref, formats);

libavfilter/formats.c:306:5: invalid access occurs here
    304. void ff_formats_unref(AVFilterFormats **ref)
    305. {
    306.     FORMATS_UNREF(ref, formats);
             ^
    307. }
    308. 
