[SCM] libav/experimental: Fix the av_set_string() free / alloc issue.

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 16:24:58 UTC 2013


The following commit has been merged in the experimental branch:
commit 8dbee6538d44570aa7c2415250b9abe00612624d
Author: Michael Niedermayer <michaelni at gmx.at>
Date:   Tue Jul 8 23:50:03 2008 +0000

    Fix the av_set_string() free / alloc issue.
    
    Originally committed as revision 14134 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/ffmpeg.c b/ffmpeg.c
index 4c13bb5..46455c1 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2203,19 +2203,19 @@ static int opt_default(const char *opt, const char *arg){
     for(type=0; type<CODEC_TYPE_NB; type++){
         const AVOption *o2 = av_find_opt(avctx_opts[0], opt, NULL, opt_types[type], opt_types[type]);
         if(o2)
-            o = av_set_string(avctx_opts[type], opt, arg);
+            o = av_set_string2(avctx_opts[type], opt, arg, 1);
     }
     if(!o)
-        o = av_set_string(avformat_opts, opt, arg);
+        o = av_set_string2(avformat_opts, opt, arg, 1);
     if(!o)
-        o = av_set_string(sws_opts, opt, arg);
+        o = av_set_string2(sws_opts, opt, arg, 1);
     if(!o){
         if(opt[0] == 'a')
-            o = av_set_string(avctx_opts[CODEC_TYPE_AUDIO], opt+1, arg);
+            o = av_set_string2(avctx_opts[CODEC_TYPE_AUDIO], opt+1, arg, 1);
         else if(opt[0] == 'v')
-            o = av_set_string(avctx_opts[CODEC_TYPE_VIDEO], opt+1, arg);
+            o = av_set_string2(avctx_opts[CODEC_TYPE_VIDEO], opt+1, arg, 1);
         else if(opt[0] == 's')
-            o = av_set_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt+1, arg);
+            o = av_set_string2(avctx_opts[CODEC_TYPE_SUBTITLE], opt+1, arg, 1);
     }
     if(!o)
         return -1;
@@ -2694,7 +2694,7 @@ static void set_context_opts(void *ctx, void *opts_ctx, int flags)
         const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf));
         /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
         if(str && ((opt->flags & flags) == flags))
-            av_set_string(ctx, opt_names[i], str);
+            av_set_string2(ctx, opt_names[i], str, 1);
     }
 }
 
diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index 321bf6c..3e10380 100644
--- a/libavcodec/opt.c
+++ b/libavcodec/opt.c
@@ -115,7 +115,7 @@ static int hexchar2int(char c) {
     return -1;
 }
 
-const AVOption *av_set_string(void *obj, const char *name, const char *val){
+const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){
     const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
     if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){
         return set_all_opt(obj, o->unit, o->default_val);
@@ -195,10 +195,19 @@ const AVOption *av_set_string(void *obj, const char *name, const char *val){
         return NULL;
     }
 
+    if(alloc){
+        av_free((void*)(((uint8_t*)obj) + o->offset));
+        val= av_strdup(val);
+    }
+
     memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val));
     return o;
 }
 
+const AVOption *av_set_string(void *obj, const char *name, const char *val){
+    return av_set_string2(obj, name, val, 0);
+}
+
 const AVOption *av_set_double(void *obj, const char *name, double n){
     return av_set_number(obj, name, n, 1, 1);
 }
diff --git a/libavcodec/opt.h b/libavcodec/opt.h
index cbcdedc..26039f4 100644
--- a/libavcodec/opt.h
+++ b/libavcodec/opt.h
@@ -98,7 +98,17 @@ typedef struct AVOption {
  * has been found
  */
 const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
-const AVOption *av_set_string(void *obj, const char *name, const char *val);
+
+attribute_deprecated const AVOption *av_set_string(void *obj, const char *name, const char *val);
+
+/**
+ * Sets the field of obj with the given name to value.
+ * @param alloc when 1 then the old value will be av_freed() and the
+ *                     new av_strduped()
+ *              when 0 then no av_free() nor av_strdup() will be used
+ */
+const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc);
+
 const AVOption *av_set_double(void *obj, const char *name, double n);
 const AVOption *av_set_q(void *obj, const char *name, AVRational n);
 const AVOption *av_set_int(void *obj, const char *name, int64_t n);

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list