diff --git a/cmdutils.c b/cmdutils.c
index 6576eba95cc3bd3166d18fb7513780c9e30dabfe..4462858aa48e15f62e527149bd754b31bd5289d9 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -271,6 +271,7 @@ int parse_option(void *optctx, const char *opt, const char *arg,
     if (po->flags & OPT_STRING) {
         char *str;
         str = av_strdup(arg);
+        av_freep(dst);
         *(char **)dst = str;
     } else if (po->flags & OPT_BOOL) {
         *(int *)dst = bool_val;