libavformat/hlsenc.c:577: error: Use After Free
  accessing memory that was invalidated by call to `free()` on line 575 indirectly during the call to `avformat_free_context()`.

libavformat/hlsenc.c:568:1: invalidation part of the trace starts here
566. }
567. 
568. static int hls_write_trailer(struct AVFormatContext *s)
     ^
569. {
570.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:568:1: parameter `s` of hls_write_trailer
  566. }
  567. 
  568. static int hls_write_trailer(struct AVFormatContext *s)
       ^
  569. {
  570.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:570:5: assigned
  568. static int hls_write_trailer(struct AVFormatContext *s)
  569. {
  570.     HLSContext *hls = s->priv_data;
           ^
  571.     AVFormatContext *oc = hls->avf;
  572. 

libavformat/hlsenc.c:571:5: assigned
  569. {
  570.     HLSContext *hls = s->priv_data;
  571.     AVFormatContext *oc = hls->avf;
           ^
  572. 
  573.     av_write_trailer(oc);

libavformat/hlsenc.c:575:5: when calling `avformat_free_context` here
  573.     av_write_trailer(oc);
  574.     ff_format_io_close(s, &oc->pb);
  575.     avformat_free_context(oc);
           ^
  576.     av_free(hls->basename);
  577.     append_entry(hls, hls->duration, av_basename(hls->avf->filename));

libavformat/utils.c:2701:1: parameter `s` of avformat_free_context
    2699. }
    2700. 
    2701. void avformat_free_context(AVFormatContext *s)
          ^
    2702. {
    2703.     int i;

libavformat/utils.c:2730:5: when calling `av_free` here
    2728.     av_freep(&s->streams);
    2729.     av_freep(&s->internal);
    2730.     av_free(s);
              ^
    2731. }
    2732. 

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

libavutil/mem.c:189:5: was invalidated by call to `free()`
      187.     _aligned_free(ptr);
      188. #else
      189.     free(ptr);
               ^
      190. #endif
      191. }

libavformat/hlsenc.c:568:1: use-after-lifetime part of the trace starts here
566. }
567. 
568. static int hls_write_trailer(struct AVFormatContext *s)
     ^
569. {
570.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:568:1: parameter `s` of hls_write_trailer
  566. }
  567. 
  568. static int hls_write_trailer(struct AVFormatContext *s)
       ^
  569. {
  570.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:570:5: assigned
  568. static int hls_write_trailer(struct AVFormatContext *s)
  569. {
  570.     HLSContext *hls = s->priv_data;
           ^
  571.     AVFormatContext *oc = hls->avf;
  572. 

libavformat/hlsenc.c:577:38: invalid access occurs here
  575.     avformat_free_context(oc);
  576.     av_free(hls->basename);
  577.     append_entry(hls, hls->duration, av_basename(hls->avf->filename));
                                            ^
  578.     hls_window(s, 1);
  579. 

static int hls_write_trailer(struct AVFormatContext *s)
{
    HLSContext *hls = s->priv_data;
    AVFormatContext *oc = hls->avf;
    av_write_trailer(oc);
    ff_format_io_close(s, &oc->pb);
    avformat_free_context(oc);
    av_free(hls->basename);
    append_entry(hls, hls->duration, av_basename(hls->avf->filename));
    hls_window(s, 1);
    free_entries(hls);
    free_encryption(s);
    return 0;
}
['static int hls_write_trailer(struct AVFormatContext *s)\n{\n    HLSContext *hls = s->priv_data;\n    AVFormatContext *oc = hls->avf;\n    av_write_trailer(oc);\n    ff_format_io_close(s, &oc->pb);\n    avformat_free_context(oc);\n    av_free(hls->basename);\n    append_entry(hls, hls->duration, av_basename(hls->avf->filename));\n    hls_window(s, 1);\n    free_entries(hls);\n    free_encryption(s);\n    return 0;\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n    int i;\n    if (!s)\n        return;\n    av_opt_free(s);\n    if (s->iformat && s->iformat->priv_class && s->priv_data)\n        av_opt_free(s->priv_data);\n    for (i = 0; i < s->nb_streams; i++)\n        free_stream(&s->streams[i]);\n    for (i = s->nb_programs - 1; i >= 0; i--) {\n        av_dict_free(&s->programs[i]->metadata);\n        av_freep(&s->programs[i]->stream_index);\n        av_freep(&s->programs[i]);\n    }\n    av_freep(&s->programs);\n    av_freep(&s->priv_data);\n    while (s->nb_chapters--) {\n        av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n        av_free(s->chapters[s->nb_chapters]);\n    }\n    av_freep(&s->chapters);\n    av_dict_free(&s->metadata);\n    av_freep(&s->streams);\n    av_freep(&s->internal);\n    av_free(s);\n}', 'void av_free(void *ptr)\n{\n#if HAVE_ALIGNED_MALLOC\n    _aligned_free(ptr);\n#else\n    free(ptr);\n#endif\n}']