Skip to content
Snippets Groups Projects
Commit 1d81f744 authored by Paweł Hajdan, Jr's avatar Paweł Hajdan, Jr Committed by Michael Niedermayer
Browse files

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.html



Signed-off-by: default avatarPaweł Hajdan, Jr <phajdan@google.com>
Signed-off-by: default avatarMichael Niedermayer <michaelni@gmx.at>
parent 0dfc01c2
No related branches found
No related tags found
No related merge requests found
...@@ -94,10 +94,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags ...@@ -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; m->elems[m->count].value = (char*)(intptr_t)value;
} else if (oldval && flags & AV_DICT_APPEND) { } else if (oldval && flags & AV_DICT_APPEND) {
int len = strlen(oldval) + strlen(value) + 1; int len = strlen(oldval) + strlen(value) + 1;
if (!(oldval = av_realloc(oldval, len))) char *newval = av_mallocz(len);
if (!newval)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
av_strlcat(oldval, value, len); av_strlcat(newval, oldval, len);
m->elems[m->count].value = oldval; av_strlcat(newval, value, len);
m->elems[m->count].value = newval;
} else } else
m->elems[m->count].value = av_strdup(value); m->elems[m->count].value = av_strdup(value);
m->count++; m->count++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment