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

libavformat/segment.c:174:9: Assignment
172.     if (ret) {
173.         oc->streams = NULL;
174.         oc->nb_streams = 0;
             ^
175.         if (seg->list)
176.             avio_close(seg->pb);

libavformat/segment.c:177:9: Call
175.         if (seg->list)
176.             avio_close(seg->pb);
177.         avformat_free_context(oc);
             ^
178.     }
179.     return ret;

libavformat/utils.c:2650:1: <LHS trace>
2648. #endif
2649. 
2650. void avformat_free_context(AVFormatContext *s)
      ^
2651. {
2652.     int i;

libavformat/utils.c:2650:1: Parameter `s->nb_chapters`
  2648. #endif
  2649. 
  2650. void avformat_free_context(AVFormatContext *s)
        ^
  2651. {
  2652.     int i;

libavformat/utils.c:2682:11: Binary operation: ([-oo, 0] - 1):unsigned32 by call to `avformat_free_context` 
  2680.     av_freep(&s->programs);
  2681.     av_freep(&s->priv_data);
  2682.     while(s->nb_chapters--) {
                  ^
  2683.         av_dict_free(&s->chapters[s->nb_chapters]->metadata);
  2684.         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);
            av_free_packet(&st->cur_pkt);
        }
        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_header(AVFormatContext *s)\n{\n    SegmentContext *seg = s->priv_data;\n    AVFormatContext *oc;\n    int ret, i;\n    seg->number = 0;\n    seg->offset_time = 0;\n    seg->recording_time = seg->time * 1000000;\n    if (seg->list)\n        if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,\n                              &s->interrupt_callback, NULL)) < 0)\n            return ret;\n    for (i = 0; i< s->nb_streams; i++)\n        seg->has_video +=\n            (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO);\n    if (seg->has_video > 1)\n        av_log(s, AV_LOG_WARNING,\n               "More than a single video stream present, "\n               "expect issues decoding it.\\n");\n    oc = avformat_alloc_context();\n    if (!oc) {\n        ret = AVERROR(ENOMEM);\n        goto fail;\n    }\n    oc->oformat = av_guess_format(seg->format, s->filename, NULL);\n    if (!oc->oformat) {\n        ret = AVERROR_MUXER_NOT_FOUND;\n        goto fail;\n    }\n    if (oc->oformat->flags & AVFMT_NOFILE) {\n        av_log(s, AV_LOG_ERROR, "format %s not supported.\\n",\n               oc->oformat->name);\n        ret = AVERROR(EINVAL);\n        goto fail;\n    }\n    seg->avf = oc;\n    oc->streams = s->streams;\n    oc->nb_streams = s->nb_streams;\n    if (av_get_frame_filename(oc->filename, sizeof(oc->filename),\n                              s->filename, seg->number++) < 0) {\n        ret = AVERROR(EINVAL);\n        goto fail;\n    }\n    if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,\n                          &s->interrupt_callback, NULL)) < 0)\n        goto fail;\n    if ((ret = avformat_write_header(oc, NULL)) < 0) {\n        avio_close(oc->pb);\n        goto fail;\n    }\n    if (seg->list) {\n        avio_printf(seg->pb, "%s\\n", oc->filename);\n        avio_flush(seg->pb);\n    }\nfail:\n    if (ret) {\n        oc->streams = NULL;\n        oc->nb_streams = 0;\n        if (seg->list)\n            avio_close(seg->pb);\n        avformat_free_context(oc);\n    }\n    return ret;\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            av_free_packet(&st->cur_pkt);\n        }\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}']