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

libavformat/hlsenc.c:322:1: invalidation part of the trace starts here
320. }
321. 
322. static int hls_write_trailer(struct AVFormatContext *s)
     ^
323. {
324.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:322:1: parameter `s` of hls_write_trailer
  320. }
  321. 
  322. static int hls_write_trailer(struct AVFormatContext *s)
       ^
  323. {
  324.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:324:5: assigned
  322. static int hls_write_trailer(struct AVFormatContext *s)
  323. {
  324.     HLSContext *hls = s->priv_data;
           ^
  325.     AVFormatContext *oc = hls->avf;
  326. 

libavformat/hlsenc.c:325:5: assigned
  323. {
  324.     HLSContext *hls = s->priv_data;
  325.     AVFormatContext *oc = hls->avf;
           ^
  326. 
  327.     av_write_trailer(oc);

libavformat/hlsenc.c:329:5: when calling `avformat_free_context` here
  327.     av_write_trailer(oc);
  328.     ff_format_io_close(s, &oc->pb);
  329.     avformat_free_context(oc);
           ^
  330.     av_free(hls->basename);
  331.     append_entry(hls, hls->duration);

libavformat/utils.c:2598:1: parameter `s` of avformat_free_context
    2596. }
    2597. 
    2598. void avformat_free_context(AVFormatContext *s)
          ^
    2599. {
    2600.     int i;

libavformat/utils.c:2627:5: when calling `av_free` here
    2625.     av_freep(&s->streams);
    2626.     av_freep(&s->internal);
    2627.     av_free(s);
              ^
    2628. }
    2629. 

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:322:1: use-after-lifetime part of the trace starts here
320. }
321. 
322. static int hls_write_trailer(struct AVFormatContext *s)
     ^
323. {
324.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:322:1: parameter `s` of hls_write_trailer
  320. }
  321. 
  322. static int hls_write_trailer(struct AVFormatContext *s)
       ^
  323. {
  324.     HLSContext *hls = s->priv_data;

libavformat/hlsenc.c:324:5: assigned
  322. static int hls_write_trailer(struct AVFormatContext *s)
  323. {
  324.     HLSContext *hls = s->priv_data;
           ^
  325.     AVFormatContext *oc = hls->avf;
  326. 

libavformat/hlsenc.c:331:5: when calling `append_entry` here
  329.     avformat_free_context(oc);
  330.     av_free(hls->basename);
  331.     append_entry(hls, hls->duration);
           ^
  332.     hls_window(s, 1);
  333. 

libavformat/hlsenc.c:93:1: parameter `hls` of append_entry
    91. }
    92. 
    93. static int append_entry(HLSContext *hls, int64_t duration)
        ^
    94. {
    95.     ListEntry *en = av_malloc(sizeof(*en));

libavformat/hlsenc.c:100:26: invalid access occurs here
     98.         return AVERROR(ENOMEM);
     99. 
    100.     av_strlcpy(en->name, av_basename(hls->avf->filename), sizeof(en->name));
                                  ^
    101. 
    102.     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    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}']