[FFmpeg-devel] [PATCH 1/2] lavu/dict: fix set function when reuse existing key pointer

Lukasz Marek lukasz.m.luki2 at gmail.com
Thu Apr 2 23:20:55 CEST 2015


On 02.04.2015 01:09, Michael Niedermayer wrote:
> On Thu, Apr 02, 2015 at 12:37:34AM +0200, Lukasz Marek wrote:
>> On 01.04.2015 04:33, Michael Niedermayer wrote:
>>> On Wed, Apr 01, 2015 at 03:25:23AM +0200, Lukasz Marek wrote:
>>>> Fixes following scenario:
>>>>
>>>> av_dict_set(&d, "key", "old", 0);
>>>> AVDictionaryEentry *e = av_dict_get(d, "key", NULL, 0);
>>>> av_dict_set(&d, e->key, "new", 0);
>>>>
>>>> Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
>>>> ---
>>>>   libavutil/dict.c | 18 ++++++++++++++++--
>>>>   1 file changed, 16 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/libavutil/dict.c b/libavutil/dict.c
>>>> index 0d54c79..3163894 100644
>>>> --- a/libavutil/dict.c
>>>> +++ b/libavutil/dict.c
>>>> @@ -72,6 +72,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
>>>>       AVDictionary *m = *pm;
>>>>       AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);
>>>>       char *oldval = NULL;
>>>> +    int the_same_key = 0;
>>>>
>>>
>>> does it work to av_strdup() both key and value if they need to be
>>> strduped but at the top of the function and simplify the rest
>>> accordingly ?
>>
>>
>> something like attached?
>
> yes, LGTM if tested with valgrind or similar

Yes, I've tested with valgrind. Pushed.



More information about the ffmpeg-devel mailing list