demux: fix segmentation fault with avformat_close_input