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

libavformat/segment.c:322:11: Call
320.     }
321. 
322.     ret = ff_write_chained(oc, pkt->stream_index, pkt, s);
               ^
323. 
324. fail:

libavformat/mux.c:656:12: Call
  654.                                      src->streams[pkt->stream_index]->time_base,
  655.                                      dst->streams[dst_stream]->time_base);
  656.     return av_write_frame(dst, &local_pkt);
                  ^
  657. }

libavformat/mux.c:402:9: Assignment
    400. 
    401.     if (ret >= 0)
    402.         s->streams[pkt->stream_index]->nb_frames++;
                 ^
    403.     return ret;
    404. }

libavformat/segment.c:328:9: Call
326.         if (seg->list)
327.             avio_close(seg->pb);
328.         avformat_free_context(oc);
             ^
329.     }
330. 

libavformat/utils.c:2432:1: <LHS trace>
2430. }
2431. 
2432. void avformat_free_context(AVFormatContext *s)
      ^
2433. {
2434.     int i, j;

libavformat/utils.c:2432:1: Parameter `s->nb_programs`
  2430. }
  2431. 
  2432. void avformat_free_context(AVFormatContext *s)
        ^
  2433. {
  2434.     int i, j;

libavformat/utils.c:2468:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `avformat_free_context` 
  2466.         av_free(st);
  2467.     }
  2468.     for (i = s->nb_programs - 1; i >= 0; i--) {
                 ^
  2469.         av_dict_free(&s->programs[i]->metadata);
  2470.         av_freep(&s->programs[i]->stream_index);

void avformat_free_context(AVFormatContext *s)
{
    int i, j;
    AVStream *st;
    if (!s)
        return;
    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];
        for (j = 0; j < st->nb_side_data; j++)
            av_freep(&st->side_data[j].data);
        av_freep(&st->side_data);
        st->nb_side_data = 0;
        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_freep(&st->probe_data.buf);
        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_freep(&s->internal);
    av_free(s);
}
['static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)\n{\n    SegmentContext *seg = s->priv_data;\n    AVFormatContext *oc = seg->avf;\n    AVStream *st = s->streams[pkt->stream_index];\n    int64_t end_pts = seg->recording_time * seg->number;\n    int ret, can_split = 1;\n    if (seg->has_video) {\n        can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&\n                    pkt->flags & AV_PKT_FLAG_KEY;\n    }\n    if (can_split && av_compare_ts(pkt->pts, st->time_base, end_pts,\n                                   AV_TIME_BASE_Q) >= 0) {\n        av_log(s, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\\n",\n               pkt->stream_index, pkt->pts);\n        ret = segment_end(oc, seg->individual_header_trailer);\n        if (!ret)\n            ret = segment_start(s, seg->individual_header_trailer);\n        if (ret)\n            goto fail;\n        oc = seg->avf;\n        if (seg->list) {\n            if (seg->list_type == LIST_HLS) {\n                if ((ret = segment_hls_window(s, 0)) < 0)\n                    goto fail;\n            } else {\n                avio_printf(seg->pb, "%s\\n", oc->filename);\n                avio_flush(seg->pb);\n                if (seg->size && !(seg->number % seg->size)) {\n                    avio_closep(&seg->pb);\n                    if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,\n                                          &s->interrupt_callback, NULL)) < 0)\n                        goto fail;\n                }\n            }\n        }\n    }\n    ret = ff_write_chained(oc, pkt->stream_index, pkt, s);\nfail:\n    if (ret < 0) {\n        if (seg->list)\n            avio_close(seg->pb);\n        avformat_free_context(oc);\n    }\n    return ret;\n}', 'int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,\n                     AVFormatContext *src)\n{\n    AVPacket local_pkt;\n    local_pkt = *pkt;\n    local_pkt.stream_index = dst_stream;\n    if (pkt->pts != AV_NOPTS_VALUE)\n        local_pkt.pts = av_rescale_q(pkt->pts,\n                                     src->streams[pkt->stream_index]->time_base,\n                                     dst->streams[dst_stream]->time_base);\n    if (pkt->dts != AV_NOPTS_VALUE)\n        local_pkt.dts = av_rescale_q(pkt->dts,\n                                     src->streams[pkt->stream_index]->time_base,\n                                     dst->streams[dst_stream]->time_base);\n    return av_write_frame(dst, &local_pkt);\n}', 'int av_write_frame(AVFormatContext *s, AVPacket *pkt)\n{\n    int ret;\n    ret = check_packet(s, pkt);\n    if (ret < 0)\n        return ret;\n    if (!pkt) {\n        if (s->oformat->flags & AVFMT_ALLOW_FLUSH)\n            return s->oformat->write_packet(s, pkt);\n        return 1;\n    }\n    ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);\n    if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))\n        return ret;\n    ret = write_packet(s, pkt);\n    if (ret >= 0)\n        s->streams[pkt->stream_index]->nb_frames++;\n    return ret;\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n    int i, j;\n    AVStream *st;\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        st = s->streams[i];\n        for (j = 0; j < st->nb_side_data; j++)\n            av_freep(&st->side_data[j].data);\n        av_freep(&st->side_data);\n        st->nb_side_data = 0;\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_freep(&st->probe_data.buf);\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_freep(&s->internal);\n    av_free(s);\n}']