diff --git a/libavformat/mov.c b/libavformat/mov.c
index cc2dc87f330d61b49e092ce6c5e5367a6ca8851d..fdf9c8dc29b94a903f1aef80e496b935a30b225e 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3040,12 +3040,8 @@ static int mov_read_close(AVFormatContext *s)
     }
 
     if (mov->dv_demux) {
-        for (i = 0; i < mov->dv_fctx->nb_streams; i++) {
-            av_freep(&mov->dv_fctx->streams[i]->codec);
-            av_freep(&mov->dv_fctx->streams[i]);
-        }
-        av_freep(&mov->dv_fctx);
-        av_freep(&mov->dv_demux);
+        avformat_free_context(mov->dv_fctx);
+        mov->dv_fctx = NULL;
     }
 
     av_freep(&mov->trex_data);