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 exit_program(int ret)\n{\n    int i;\n    for(i=0;i<nb_output_files;i++) {\n        AVFormatContext *s = output_files[i].ctx;\n        if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)\n            avio_close(s->pb);\n        avformat_free_context(s);\n        av_dict_free(&output_files[i].opts);\n    }\n    for(i=0;i<nb_input_files;i++) {\n        av_close_input_file(input_files[i].ctx);\n    }\n    for (i = 0; i < nb_input_streams; i++)\n        av_dict_free(&input_streams[i].opts);\n    av_free(intra_matrix);\n    av_free(inter_matrix);\n    if (vstats_file)\n        fclose(vstats_file);\n    av_free(vstats_filename);\n    av_free(meta_data_maps);\n    av_freep(&input_streams);\n    av_freep(&input_files);\n    av_freep(&output_streams);\n    av_freep(&output_files);\n    uninit_opts();\n    av_free(audio_buf);\n    av_free(audio_out);\n    allocated_audio_buf_size= allocated_audio_out_size= 0;\n    av_free(samples);\n#if CONFIG_AVFILTER\n    avfilter_uninit();\n#endif\n    if (received_sigterm) {\n        fprintf(stderr,\n            "Received signal %d: terminating.\\n",\n            (int) received_sigterm);\n        exit (255);\n    }\n    exit(ret);\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}', 'void av_free_packet(AVPacket *pkt)\n{\n    if (pkt) {\n        if (pkt->destruct) pkt->destruct(pkt);\n        pkt->data = NULL; pkt->size = 0;\n        pkt->side_data       = NULL;\n        pkt->side_data_elems = 0;\n    }\n}', 'void av_dict_free(AVDictionary **pm)\n{\n    AVDictionary *m = *pm;\n    if (m) {\n        while(m->count--) {\n            av_free(m->elems[m->count].key);\n            av_free(m->elems[m->count].value);\n        }\n        av_free(m->elems);\n    }\n    av_freep(pm);\n}']