--- a/libmpcodecs/ad_spdif.c 2016-03-06 08:00:49.000000000 -0500 +++ b/libmpcodecs/ad_spdif.c 2021-09-09 10:22:49.000000000 -0400 @@ -298,14 +298,8 @@ if (spdif_ctx->header_written) av_write_trailer(lavf_ctx); av_freep(&lavf_ctx->pb); - if (lavf_ctx->streams) { - av_freep(&lavf_ctx->streams[0]->codec); - av_freep(&lavf_ctx->streams[0]->info); - av_freep(&lavf_ctx->streams[0]); - } - av_freep(&lavf_ctx->streams); - av_freep(&lavf_ctx->priv_data); + avformat_free_context(lavf_ctx); + lavf_ctx = NULL; } - av_freep(&lavf_ctx); av_freep(&spdif_ctx); }