[FFmpeg-cvslog] dict.c: use av_mallocz instead of av_realloc
=?UTF-8?Q?Pawe=C5=82=20Hajdan?=, Jr
git at videolan.org
Tue Jan 29 22:55:19 CET 2013
ffmpeg | branch: master | Paweł Hajdan, Jr <phajdan at google.com> | Tue Jan 29 11:41:10 2013 +0000| [1d81f7448c8aa7df4aaed612fcd032dbccbd1a96] | committer: 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.html
Signed-off-by: Paweł Hajdan, Jr <phajdan at google.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1d81f7448c8aa7df4aaed612fcd032dbccbd1a96
---
libavutil/dict.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/libavutil/dict.c b/libavutil/dict.c
index 06f963c..23816e8 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -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++;
More information about the ffmpeg-cvslog
mailing list