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

libavformat/avidec.c:1298:13: Call
1296.         av_free(st->codec->palctrl);
1297.         if (ast->sub_ctx) {
1298.             av_freep(&ast->sub_ctx->pb);
                  ^
1299.             av_close_input_stream(ast->sub_ctx);
1300.         }

libavutil/mem.c:154:5: Assignment
  152.     void **ptr= (void**)arg;
  153.     av_free(*ptr);
  154.     *ptr = NULL;
           ^
  155. }
  156. 

libavformat/avidec.c:1299:13: Call
1297.         if (ast->sub_ctx) {
1298.             av_freep(&ast->sub_ctx->pb);
1299.             av_close_input_stream(ast->sub_ctx);
                  ^
1300.         }
1301.         av_free(ast->sub_buffer);

libavformat/utils.c:2444:1: <LHS trace>
2442. }
2443. 
2444. void av_close_input_stream(AVFormatContext *s)
      ^
2445. {
2446.     int i;

libavformat/utils.c:2444:1: Parameter `s->nb_chapters`
  2442. }
  2443. 
  2444. void av_close_input_stream(AVFormatContext *s)
        ^
  2445. {
  2446.     int i;

libavformat/utils.c:2480:11: Binary operation: ([-oo, 0] - 1):unsigned32 by call to `av_close_input_stream` 
  2478.     flush_packet_queue(s);
  2479.     av_freep(&s->priv_data);
  2480.     while(s->nb_chapters--) {
                  ^
  2481. #if LIBAVFORMAT_VERSION_INT < (53<<16)
  2482.         av_free(s->chapters[s->nb_chapters]->title);

void av_close_input_stream(AVFormatContext *s)
{
    int i;
    AVStream *st;
    if (s->iformat->read_close)
        s->iformat->read_close(s);
    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_metadata_free(&st->metadata);
        av_free(st->index_entries);
        av_free(st->codec->extradata);
        av_free(st->codec);
#if LIBAVFORMAT_VERSION_INT < (53<<16)
        av_free(st->filename);
#endif
        av_free(st->priv_data);
        av_free(st);
    }
    for(i=s->nb_programs-1; i>=0; i--) {
#if LIBAVFORMAT_VERSION_INT < (53<<16)
        av_freep(&s->programs[i]->provider_name);
        av_freep(&s->programs[i]->name);
#endif
        av_metadata_free(&s->programs[i]->metadata);
        av_freep(&s->programs[i]->stream_index);
        av_freep(&s->programs[i]);
    }
    av_freep(&s->programs);
    flush_packet_queue(s);
    av_freep(&s->priv_data);
    while(s->nb_chapters--) {
#if LIBAVFORMAT_VERSION_INT < (53<<16)
        av_free(s->chapters[s->nb_chapters]->title);
#endif
        av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
        av_free(s->chapters[s->nb_chapters]);
    }
    av_freep(&s->chapters);
    av_metadata_free(&s->metadata);
    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        av_free(st->codec->palctrl);\n        if (ast->sub_ctx) {\n            av_freep(&ast->sub_ctx->pb);\n            av_close_input_stream(ast->sub_ctx);\n        }\n        av_free(ast->sub_buffer);\n        av_free_packet(&ast->sub_pkt);\n    }\n    if (avi->dv_demux)\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 av_close_input_stream(AVFormatContext *s)\n{\n    int i;\n    AVStream *st;\n    if (s->iformat->read_close)\n        s->iformat->read_close(s);\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_metadata_free(&st->metadata);\n        av_free(st->index_entries);\n        av_free(st->codec->extradata);\n        av_free(st->codec);\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n        av_free(st->filename);\n#endif\n        av_free(st->priv_data);\n        av_free(st);\n    }\n    for(i=s->nb_programs-1; i>=0; i--) {\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n        av_freep(&s->programs[i]->provider_name);\n        av_freep(&s->programs[i]->name);\n#endif\n        av_metadata_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    flush_packet_queue(s);\n    av_freep(&s->priv_data);\n    while(s->nb_chapters--) {\n#if LIBAVFORMAT_VERSION_INT < (53<<16)\n        av_free(s->chapters[s->nb_chapters]->title);\n#endif\n        av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n        av_free(s->chapters[s->nb_chapters]);\n    }\n    av_freep(&s->chapters);\n    av_metadata_free(&s->metadata);\n    av_free(s);\n}']