[FFmpeg-devel] [PATCH 09/11] avutil/dict: Fix memleak when using AV_DICT_APPEND
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Mon Nov 11 03:12:57 EET 2019
If a key already exists in an AVDictionary and the AV_DICT_APPEND flag
is set, the old entry is at first discarded from the dictionary, but
a pointer to the value is kept. Lateron enough memory to store the
appended string is allocated; should this allocation fail, the old string
is not freed and hence leaks. This commit changes this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavutil/dict.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libavutil/dict.c b/libavutil/dict.c
index 0ea71386e5..190ef196be 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -115,8 +115,10 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
if (oldval && flags & AV_DICT_APPEND) {
size_t len = strlen(oldval) + strlen(copy_value) + 1;
char *newval = av_mallocz(len);
- if (!newval)
+ if (!newval) {
+ av_free(oldval);
goto err_out;
+ }
av_strlcat(newval, oldval, len);
av_freep(&oldval);
av_strlcat(newval, copy_value, len);
--
2.20.1
More information about the ffmpeg-devel
mailing list