libavfilter/af_join.c:259: error: Use After Free
  accessing memory that was invalidated by call to `free()` on line 258 indirectly during the call to `ff_add_channel_layout()`.

libavfilter/af_join.c:255:5: invalidation part of the trace starts here
253. {
254.     JoinContext *s = ctx->priv;
255.     AVFilterChannelLayouts *layouts = NULL;
         ^
256.     int i;
257. 

libavfilter/af_join.c:255:5: variable `layouts` declared here
  253. {
  254.     JoinContext *s = ctx->priv;
  255.     AVFilterChannelLayouts *layouts = NULL;
           ^
  256.     int i;
  257. 

libavfilter/af_join.c:258:5: when calling `ff_add_channel_layout` here
  256.     int i;
  257. 
  258.     ff_add_channel_layout(&layouts, s->channel_layout);
           ^
  259.     ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
  260. 

libavfilter/formats.c:206:1: parameter `l` of ff_add_channel_layout
    204. }
    205. 
    206. int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
         ^
    207. {
    208.     ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);

libavfilter/formats.c:208:5: when calling `av_freep` here
    206. int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
    207. {
    208.     ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);
             ^
    209. }
    210. 

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/af_join.c:255:5: use-after-lifetime part of the trace starts here
253. {
254.     JoinContext *s = ctx->priv;
255.     AVFilterChannelLayouts *layouts = NULL;
         ^
256.     int i;
257. 

libavfilter/af_join.c:255:5: variable `layouts` declared here
  253. {
  254.     JoinContext *s = ctx->priv;
  255.     AVFilterChannelLayouts *layouts = NULL;
           ^
  256.     int i;
  257. 

libavfilter/af_join.c:259:28: invalid access occurs here
  257. 
  258.     ff_add_channel_layout(&layouts, s->channel_layout);
  259.     ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
                                  ^
  260. 
  261.     for (i = 0; i < ctx->nb_inputs; i++)

static int join_query_formats(AVFilterContext *ctx)
{
    JoinContext *s = ctx->priv;
    AVFilterChannelLayouts *layouts = NULL;
    int i;
    ff_add_channel_layout(&layouts, s->channel_layout);
    ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
    for (i = 0; i < ctx->nb_inputs; i++)
        ff_channel_layouts_ref(ff_all_channel_layouts(),
                               &ctx->inputs[i]->out_channel_layouts);
    ff_set_common_formats    (ctx, ff_planar_sample_fmts());
    ff_set_common_samplerates(ctx, ff_all_samplerates());
    return 0;
}
['static int join_query_formats(AVFilterContext *ctx)\n{\n    JoinContext *s = ctx->priv;\n    AVFilterChannelLayouts *layouts = NULL;\n    int i;\n    ff_add_channel_layout(&layouts, s->channel_layout);\n    ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);\n    for (i = 0; i < ctx->nb_inputs; i++)\n        ff_channel_layouts_ref(ff_all_channel_layouts(),\n                               &ctx->inputs[i]->out_channel_layouts);\n    ff_set_common_formats    (ctx, ff_planar_sample_fmts());\n    ff_set_common_samplerates(ctx, ff_all_samplerates());\n    return 0;\n}', 'int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)\n{\n    ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);\n}', 'void av_freep(void *arg)\n{\n    void **ptr = (void **)arg;\n    av_free(*ptr);\n    *ptr = NULL;\n}', 'void av_free(void *ptr)\n{\n#if CONFIG_MEMALIGN_HACK\n    if (ptr)\n        free((char *)ptr - ((char *)ptr)[-1]);\n#elif HAVE_ALIGNED_MALLOC\n    _aligned_free(ptr);\n#else\n    free(ptr);\n#endif\n}']