Commit 1d81f744 authored by Paweł Hajdan, Jr's avatar Paweł Hajdan, Jr Committed by Michael Niedermayer

dict.c: use av_mallocz instead of av_realloc

Memory passed to av_realloc must come from malloc,
calloc or realloc, and not e.g. memalign. realloc(3):

The realloc() function changes the size of the memory block pointed to
by ptr to size bytes. (...) Unless ptr is NULL, it must have been
returned by an earlier call to malloc(), calloc() or realloc().

The issue has been found by debugallocation, a part of google-perftools:
http://code.google.com/p/gperftools/ .

This makes fate pass when using LD_PRELOAD-ed debugallocation.

See also earlier discussion
http://ffmpeg.org/pipermail/ffmpeg-devel/2013-January/137234.htmlSigned-off-by: 's avatarPaweł Hajdan, Jr <phajdan@google.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 0dfc01c2
......@@ -94,10 +94,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags
m->elems[m->count].value = (char*)(intptr_t)value;
} else if (oldval && flags & AV_DICT_APPEND) {
int len = strlen(oldval) + strlen(value) + 1;
if (!(oldval = av_realloc(oldval, len)))
char *newval = av_mallocz(len);
if (!newval)
return AVERROR(ENOMEM);
av_strlcat(oldval, value, len);
m->elems[m->count].value = oldval;
av_strlcat(newval, oldval, len);
av_strlcat(newval, value, len);
m->elems[m->count].value = newval;
} else
m->elems[m->count].value = av_strdup(value);
m->count++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment