diff --git a/cmdutils.c b/cmdutils.c
index feeea694d818f0e76470b83d8c0abdff910d42b6..778f0fb3cf5deebc3bbbf65cb6651b5c77e3cf9d 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -76,7 +76,8 @@ void uninit_opts(void)
     av_freep(&avformat_opts->key);
     av_freep(&avformat_opts);
 #if CONFIG_SWSCALE
-    av_freep(&sws_opts);
+    sws_freeContext(sws_opts);
+    sws_opts = NULL;
 #endif
     for (i = 0; i < opt_name_count; i++) {
         //opt_values are only stored for codec-specific options in which case