libavformat/avidec.c:1369: error: Integer Overflow L1
  ([-oo, 0] - 1):unsigned32 by call to `avformat_close_input`.

libavformat/avidec.c:1368:17: Call
1366.         if (ast) {
1367.             if (ast->sub_ctx) {
1368.                 av_freep(&ast->sub_ctx->pb);
                      ^
1369.                 avformat_close_input(&ast->sub_ctx);
1370.             }

libavutil/mem.c:151:5: Assignment
  149.     void **ptr= (void**)arg;
  150.     av_free(*ptr);
  151.     *ptr = NULL;
           ^
  152. }
  153. 

libavformat/avidec.c:1369:17: Call
1367.             if (ast->sub_ctx) {
1368.                 av_freep(&ast->sub_ctx->pb);
1369.                 avformat_close_input(&ast->sub_ctx);
                      ^
1370.             }
1371.             av_free(ast->sub_buffer);

libavformat/utils.c:2594:1: Parameter `(*ps)->nb_chapters`
  2592. #endif
  2593. 
  2594. void avformat_close_input(AVFormatContext **ps)
        ^
  2595. {
  2596.     AVFormatContext *s = *ps;

libavformat/utils.c:2602:5: Call
  2600.     if (s->iformat->read_close)
  2601.         s->iformat->read_close(s);
  2602.     avformat_free_context(s);
            ^
  2603.     *ps = NULL;
  2604.     if (pb)

libavformat/utils.c:2545:1: <LHS trace>
2543. }
2544. 
2545. void avformat_free_context(AVFormatContext *s)
      ^
2546. {
2547.     int i;

libavformat/utils.c:2545:1: Parameter `s->nb_chapters`
    2543. }
    2544. 
    2545. void avformat_free_context(AVFormatContext *s)
          ^
    2546. {
    2547.     int i;

libavformat/utils.c:2577:11: Binary operation: ([-oo, 0] - 1):unsigned32 by call to `avformat_close_input` 
    2575.     av_freep(&s->programs);
    2576.     av_freep(&s->priv_data);
    2577.     while(s->nb_chapters--) {
                    ^
    2578.         av_dict_free(&s->chapters[s->nb_chapters]->metadata);
    2579.         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 avi_read_close(AVFormatContext *s)\n{\n    int i;\n    AVIContext *avi = s->priv_data;\n    for(i=0;i<s->nb_streams;i++) {\n        AVStream *st = s->streams[i];\n        AVIStream *ast = st->priv_data;\n        if (ast) {\n            if (ast->sub_ctx) {\n                av_freep(&ast->sub_ctx->pb);\n                avformat_close_input(&ast->sub_ctx);\n            }\n            av_free(ast->sub_buffer);\n            av_free_packet(&ast->sub_pkt);\n        }\n    }\n    av_free(avi->dv_demux);\n    return 0;\n}', 'void av_freep(void *arg)\n{\n    void **ptr= (void**)arg;\n    av_free(*ptr);\n    *ptr = NULL;\n}', 'void avformat_close_input(AVFormatContext **ps)\n{\n    AVFormatContext *s = *ps;\n    AVIOContext *pb = (s->iformat->flags & AVFMT_NOFILE) || (s->flags & AVFMT_FLAG_CUSTOM_IO) ?\n                       NULL : s->pb;\n    flush_packet_queue(s);\n    if (s->iformat->read_close)\n        s->iformat->read_close(s);\n    avformat_free_context(s);\n    *ps = NULL;\n    if (pb)\n        avio_close(pb);\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}']