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

libavformat/rtpenc_mpegts.c:37:9: Call
35.     if (chain->mpegts_ctx) {
36.         av_write_trailer(chain->mpegts_ctx);
37.         ffio_free_dyn_buf(&chain->mpegts_ctx->pb);
            ^
38.         avformat_free_context(chain->mpegts_ctx);
39.     }

libavformat/aviobuf.c:1193:1: Parameter `(*s)->written`
  1191. }
  1192. 
  1193. void ffio_free_dyn_buf(AVIOContext **s)
        ^
  1194. {
  1195.     uint8_t *tmp;

libavformat/rtpenc_mpegts.c:38:9: Call
36.         av_write_trailer(chain->mpegts_ctx);
37.         ffio_free_dyn_buf(&chain->mpegts_ctx->pb);
38.         avformat_free_context(chain->mpegts_ctx);
            ^
39.     }
40.     if (chain->rtp_ctx) {

libavformat/utils.c:2705:1: <LHS trace>
2703. }
2704. 
2705. void avformat_free_context(AVFormatContext *s)
      ^
2706. {
2707.     int i;

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

libavformat/utils.c:2719:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `avformat_free_context` 
  2717.         free_stream(&s->streams[i]);
  2718. 
  2719.     for (i = s->nb_programs - 1; i >= 0; i--) {
                 ^
  2720.         av_dict_free(&s->programs[i]->metadata);
  2721.         av_freep(&s->programs[i]->stream_index);

void avformat_free_context(AVFormatContext *s)
{
    int i;
    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++)
        free_stream(&s->streams[i]);
    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 rtp_mpegts_write_close(AVFormatContext *s)\n{\n    struct MuxChain *chain = s->priv_data;\n    if (chain->mpegts_ctx) {\n        av_write_trailer(chain->mpegts_ctx);\n        ffio_free_dyn_buf(&chain->mpegts_ctx->pb);\n        avformat_free_context(chain->mpegts_ctx);\n    }\n    if (chain->rtp_ctx) {\n        av_write_trailer(chain->rtp_ctx);\n        avformat_free_context(chain->rtp_ctx);\n    }\n    return 0;\n}', 'void ffio_free_dyn_buf(AVIOContext **s)\n{\n    uint8_t *tmp;\n    if (!*s)\n        return;\n    avio_close_dyn_buf(*s, &tmp);\n    av_free(tmp);\n    *s = NULL;\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}']