libavformat/segment.c:349: error: Integer Overflow L1
  ([-oo, 0] - 1):unsigned32 by call to `avformat_free_context`.

libavformat/segment.c:336:15: Call
334.         close_null_ctx(oc->pb);
335.     } else {
336.         ret = segment_end(oc, 1);
                   ^
337.     }
338. 

libavformat/segment.c:147:1: Parameter `*oc->packet_buffer->next`
  145. }
  146. 
  147. static int segment_end(AVFormatContext *oc, int write_trailer)
       ^
  148. {
  149.     int ret = 0;

libavformat/segment.c:153:9: Call
  151.     av_write_frame(oc, NULL); /* Flush any buffered data (fragmented mp4) */
  152.     if (write_trailer)
  153.         av_write_trailer(oc);
               ^
  154.     avio_close(oc->pb);
  155. 

libavformat/mux.c:565:1: Parameter `*s->packet_buffer->next`
    563. }
    564. 
    565. int av_write_trailer(AVFormatContext *s)
         ^
    566. {
    567.     int ret, i;

libavformat/mux.c:571:15: Call
    569.     for (;; ) {
    570.         AVPacket pkt;
    571.         ret = interleave_packet(s, &pkt, NULL, 1);
                       ^
    572.         if (ret < 0) //FIXME cleanup needed for ret<0 ?
    573.             goto fail;

libavformat/mux.c:513:1: Parameter `*s->packet_buffer->next`
      511.  *         < 0 if an error occurred
      512.  */
      513. static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
           ^
      514. {
      515.     if (s->oformat->interleave_packet) {

libavformat/segment.c:348:5: Call
346. 
347. fail:
348.     avio_close(seg->pb);
         ^
349.     avformat_free_context(oc);
350.     return ret;

libavformat/aviobuf.c:757:1: Parameter `s->opaque->is_connected`
  755. }
  756. 
  757. int avio_close(AVIOContext *s)
       ^
  758. {
  759.     URLContext *h;

libavformat/segment.c:349:5: Call
347. fail:
348.     avio_close(seg->pb);
349.     avformat_free_context(oc);
         ^
350.     return ret;
351. }

libavformat/utils.c:2623:1: <LHS trace>
2621. }
2622. 
2623. void avformat_free_context(AVFormatContext *s)
      ^
2624. {
2625.     int i;

libavformat/utils.c:2623:1: Parameter `s->nb_chapters`
  2621. }
  2622. 
  2623. void avformat_free_context(AVFormatContext *s)
        ^
  2624. {
  2625.     int i;

libavformat/utils.c:2656:11: Binary operation: ([-oo, 0] - 1):unsigned32 by call to `avformat_free_context` 
  2654.     av_freep(&s->programs);
  2655.     av_freep(&s->priv_data);
  2656.     while(s->nb_chapters--) {
                  ^
  2657.         av_dict_free(&s->chapters[s->nb_chapters]->metadata);
  2658.         av_free(s->chapters[s->nb_chapters]);

void avformat_free_context(AVFormatContext *s)
{
    int i;
    AVStream *st;
    av_opt_free(s);
    if (s->iformat && s->iformat->priv_class && s->priv_data)
        av_opt_free(s->priv_data);
    for(i=0;i<s->nb_streams;i++) {
        st = s->streams[i];
        if (st->parser) {
            av_parser_close(st->parser);
        }
        if (st->attached_pic.data)
            av_free_packet(&st->attached_pic);
        av_dict_free(&st->metadata);
        av_free(st->index_entries);
        av_free(st->codec->extradata);
        av_free(st->codec->subtitle_header);
        av_free(st->codec);
        av_free(st->priv_data);
        av_free(st->info);
        av_free(st);
    }
    for(i=s->nb_programs-1; i>=0; i--) {
        av_dict_free(&s->programs[i]->metadata);
        av_freep(&s->programs[i]->stream_index);
        av_freep(&s->programs[i]);
    }
    av_freep(&s->programs);
    av_freep(&s->priv_data);
    while(s->nb_chapters--) {
        av_dict_free(&s->chapters[s->nb_chapters]->metadata);
        av_free(s->chapters[s->nb_chapters]);
    }
    av_freep(&s->chapters);
    av_dict_free(&s->metadata);
    av_freep(&s->streams);
    av_free(s);
}
['static int seg_write_trailer(struct AVFormatContext *s)\n{\n    SegmentContext *seg = s->priv_data;\n    AVFormatContext *oc = seg->avf;\n    int ret;\n    if (!seg->write_header_trailer) {\n        if ((ret = segment_end(oc, 0)) < 0)\n            goto fail;\n        open_null_ctx(&oc->pb);\n        ret = av_write_trailer(oc);\n        close_null_ctx(oc->pb);\n    } else {\n        ret = segment_end(oc, 1);\n    }\n    if (ret < 0)\n        goto fail;\n    if (seg->list && seg->list_type == LIST_HLS) {\n        if ((ret = segment_hls_window(s, 1) < 0))\n            goto fail;\n    }\nfail:\n    avio_close(seg->pb);\n    avformat_free_context(oc);\n    return ret;\n}', 'static int segment_end(AVFormatContext *oc, int write_trailer)\n{\n    int ret = 0;\n    av_write_frame(oc, NULL);\n    if (write_trailer)\n        av_write_trailer(oc);\n    avio_close(oc->pb);\n    return ret;\n}', 'int av_write_trailer(AVFormatContext *s)\n{\n    int ret, i;\n    for (;; ) {\n        AVPacket pkt;\n        ret = interleave_packet(s, &pkt, NULL, 1);\n        if (ret < 0)\n            goto fail;\n        if (!ret)\n            break;\n        ret = s->oformat->write_packet(s, &pkt);\n        if (ret >= 0)\n            s->streams[pkt.stream_index]->nb_frames++;\n        av_free_packet(&pkt);\n        if (ret < 0)\n            goto fail;\n    }\n    if (s->oformat->write_trailer)\n        ret = s->oformat->write_trailer(s);\n    if (!(s->oformat->flags & AVFMT_NOFILE))\n        avio_flush(s->pb);\nfail:\n    for (i = 0; i < s->nb_streams; i++) {\n        av_freep(&s->streams[i]->priv_data);\n        av_freep(&s->streams[i]->index_entries);\n    }\n    if (s->oformat->priv_class)\n        av_opt_free(s->priv_data);\n    av_freep(&s->priv_data);\n    return ret;\n}', 'static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)\n{\n    if (s->oformat->interleave_packet) {\n        int ret = s->oformat->interleave_packet(s, out, in, flush);\n        if (in)\n            av_free_packet(in);\n        return ret;\n    } else\n        return ff_interleave_packet_per_dts(s, out, in, flush);\n}', 'int avio_close(AVIOContext *s)\n{\n    URLContext *h;\n    if (!s)\n        return 0;\n    avio_flush(s);\n    h = s->opaque;\n    av_freep(&s->buffer);\n    av_free(s);\n    return ffurl_close(h);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n    int i;\n    AVStream *st;\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        st = s->streams[i];\n        if (st->parser) {\n            av_parser_close(st->parser);\n        }\n        if (st->attached_pic.data)\n            av_free_packet(&st->attached_pic);\n        av_dict_free(&st->metadata);\n        av_free(st->index_entries);\n        av_free(st->codec->extradata);\n        av_free(st->codec->subtitle_header);\n        av_free(st->codec);\n        av_free(st->priv_data);\n        av_free(st->info);\n        av_free(st);\n    }\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_free(s);\n}']