summaryrefslogtreecommitdiff
path: root/libavcodec/opt.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2008-07-08 23:50:03 +0000
committerMichael Niedermayer <michaelni@gmx.at>2008-07-08 23:50:03 +0000
commit8dbee6538d44570aa7c2415250b9abe00612624d (patch)
tree7f0fedf29aeeefe6480df088aa54f89548d13648 /libavcodec/opt.c
parentcdb5af79e386c73cd8194e1f7e61f4b5cc743419 (diff)
Fix the av_set_string() free / alloc issue.
Originally committed as revision 14134 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/opt.c')
-rw-r--r--libavcodec/opt.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index 321bf6cc27..3e10380222 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);
}