diff opt.c @ 7224:d5a52b28c9de libavcodec

Fix the av_set_string() free / alloc issue.
author michael
date Tue, 08 Jul 2008 23:50:03 +0000
parents 322023e630a6
children 8c58eeb20826
line wrap: on
line diff
--- a/opt.c	Tue Jul 08 16:02:20 2008 +0000
+++ b/opt.c	Tue Jul 08 23:50:03 2008 +0000
@@ -115,7 +115,7 @@
     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 @@
         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);
 }