[FFmpeg-devel] [PATCH 2/2] cmdutils: fix codec-specific options from preset

James Zern jzern
Sat Feb 5 03:00:17 CET 2011


Using a preset file caused the address of a stack variable to be stored
in opt_names/values. This change causes the strings to be dup'd then
freed in uninit_opts.
---
 cmdutils.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
-------------- next part --------------
diff --git a/cmdutils.c b/cmdutils.c
index 99e4c38..76ae856 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -78,6 +78,12 @@ void uninit_opts(void)
 #if CONFIG_SWSCALE
     av_freep(&sws_opts);
 #endif
+    for (i = 0; i < opt_name_count; i++) {
+        if (opt_values[i]) {
+            av_freep(&opt_names[i]);
+            av_freep(&opt_values[i]);
+        }
+    }
     av_freep(&opt_names);
     av_freep(&opt_values);
 }
@@ -270,9 +276,9 @@ int opt_default(const char *opt, const char *arg){
 
     //FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this
     opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
-    opt_values[opt_name_count]= o ? NULL : arg;
+    opt_values[opt_name_count]= o ? NULL : av_strdup(arg);
     opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
-    opt_names[opt_name_count++]= o ? o->name : opt;
+    opt_names[opt_name_count++]= o ? o->name : av_strdup(opt);
 
     if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug))
         av_log_set_level(AV_LOG_DEBUG);



More information about the ffmpeg-devel mailing list