libavformat/hlsenc.c:503: error: Use After Free
  call to `append_entry()` eventually accesses memory that was invalidated by call to `free()` on line 501 indirectly during the call to `avformat_free_context()`.

libavformat/hlsenc.c:494:1: invalidation part of the trace starts here
492. }
493. 
494. static int hls_write_trailer(struct AVFormatContext *s)
     ^
495. {
496.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:494:1: parameter `s` of hls_write_trailer
  492. }
  493. 
  494. static int hls_write_trailer(struct AVFormatContext *s)
       ^
  495. {
  496.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:496:5: assigned
  494. static int hls_write_trailer(struct AVFormatContext *s)
  495. {
  496.     HLSContext *hls = s->priv_data;
           ^
  497.     AVFormatContext *oc = hls->avf;
  498. 

libavformat/hlsenc.c:497:5: assigned
  495. {
  496.     HLSContext *hls = s->priv_data;
  497.     AVFormatContext *oc = hls->avf;
           ^
  498. 
  499.     av_write_trailer(oc);

libavformat/hlsenc.c:501:5: when calling `avformat_free_context` here
  499.     av_write_trailer(oc);
  500.     ff_format_io_close(s, &oc->pb);
  501.     avformat_free_context(oc);
           ^
  502.     av_free(hls->basename);
  503.     append_entry(hls, hls->duration);

libavformat/utils.c:2705:1: parameter `s` of avformat_free_context
    2703. }
    2704. 
    2705. void avformat_free_context(AVFormatContext *s)
          ^
    2706. {
    2707.     int i;

libavformat/utils.c:2734:5: when calling `av_free` here
    2732.     av_freep(&s->streams);
    2733.     av_freep(&s->internal);
    2734.     av_free(s);
              ^
    2735. }
    2736. 

libavutil/mem.c:170:1: parameter `ptr` of av_free
      168. }
      169. 
      170. void av_free(void *ptr)
           ^
      171. {
      172. #if HAVE_ALIGNED_MALLOC

libavutil/mem.c:175:5: was invalidated by call to `free()`
      173.     _aligned_free(ptr);
      174. #else
      175.     free(ptr);
               ^
      176. #endif
      177. }

libavformat/hlsenc.c:494:1: use-after-lifetime part of the trace starts here
492. }
493. 
494. static int hls_write_trailer(struct AVFormatContext *s)
     ^
495. {
496.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:494:1: parameter `s` of hls_write_trailer
  492. }
  493. 
  494. static int hls_write_trailer(struct AVFormatContext *s)
       ^
  495. {
  496.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:496:5: assigned
  494. static int hls_write_trailer(struct AVFormatContext *s)
  495. {
  496.     HLSContext *hls = s->priv_data;
           ^
  497.     AVFormatContext *oc = hls->avf;
  498. 

libavformat/hlsenc.c:503:5: when calling `append_entry` here
  501.     avformat_free_context(oc);
  502.     av_free(hls->basename);
  503.     append_entry(hls, hls->duration);
           ^
  504.     hls_window(s, 1);
  505. 

libavformat/hlsenc.c:204:1: parameter `hls` of append_entry
    202. }
    203. 
    204. static int append_entry(HLSContext *hls, int64_t duration)
         ^
    205. {
    206.     ListEntry *en = av_malloc(sizeof(*en));

libavformat/hlsenc.c:211:26: invalid access occurs here
    209.         return AVERROR(ENOMEM);
    210. 
    211.     av_strlcpy(en->name, av_basename(hls->avf->filename), sizeof(en->name));
                                  ^
    212. 
    213.     en->duration = duration;

static int append_entry(HLSContext *hls, int64_t duration)
{
    ListEntry *en = av_malloc(sizeof(*en));
    if (!en)
        return AVERROR(ENOMEM);
    av_strlcpy(en->name, av_basename(hls->avf->filename), sizeof(en->name));
    en->duration = duration;
    en->next     = NULL;
    if (!hls->list)
        hls->list = en;
    else
        hls->end_list->next = en;
    hls->end_list = en;
    if (hls->nb_entries >= hls->size) {
        en = hls->list;
        hls->list = en->next;
        av_free(en);
    } else
        hls->nb_entries++;
    hls->sequence++;
    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);\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}', 'static int append_entry(HLSContext *hls, int64_t duration)\n{\n    ListEntry *en = av_malloc(sizeof(*en));\n    if (!en)\n        return AVERROR(ENOMEM);\n    av_strlcpy(en->name, av_basename(hls->avf->filename), sizeof(en->name));\n    en->duration = duration;\n    en->next     = NULL;\n    if (!hls->list)\n        hls->list = en;\n    else\n        hls->end_list->next = en;\n    hls->end_list = en;\n    if (hls->nb_entries >= hls->size) {\n        en = hls->list;\n        hls->list = en->next;\n        av_free(en);\n    } else\n        hls->nb_entries++;\n    hls->sequence++;\n    return 0;\n}']