# HG changeset patch # User michael # Date 1215561003 0 # Node ID d5a52b28c9de311fc3fa39ee2592f80fba4ffb2a # Parent 0133a6c7480fbc1eec48996374066b06e1bf0c19 Fix the av_set_string() free / alloc issue. diff -r 0133a6c7480f -r d5a52b28c9de opt.c --- 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); } diff -r 0133a6c7480f -r d5a52b28c9de opt.h --- a/opt.h Tue Jul 08 16:02:20 2008 +0000 +++ b/opt.h Tue Jul 08 23:50:03 2008 +0000 @@ -98,7 +98,17 @@ * 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);