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

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

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

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

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

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

libavformat/utils.c:2481:11: Binary operation: ([-oo, 0] - 1):unsigned32 by call to `av_close_input_stream` 
  2479.     flush_packet_queue(s);
  2480.     av_freep(&s->priv_data);
  2481.     while(s->nb_chapters--) {
                  ^
  2482. #if FF_API_OLD_METADATA
  2483.         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 FF_API_OLD_METADATA
        av_free(st->filename);
#endif
        av_free(st->priv_data);
        av_free(st);
    }
    for(i=s->nb_programs-1; i>=0; i--) {
#if FF_API_OLD_METADATA
        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 FF_API_OLD_METADATA
        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_freep(&s->key);
    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) {\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    }\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 FF_API_OLD_METADATA\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 FF_API_OLD_METADATA\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 FF_API_OLD_METADATA\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_freep(&s->key);\n    av_free(s);\n}']