Re: [FFmpeg-devel] [PATCH 1/3] dict.c: Free non-strduped av_dict_set arguments on error.
On Tue, Jul 29, 2014 at 10:13:39PM +0200, Michael Niedermayer wrote: On Tue, Jul 29, 2014 at 09:26:48PM +0200, Reimar Döffinger wrote: Unfortunately this was not explicitly documented and thus might be very risky. But basically all uses I saw in FFmpeg had a memleak in these cases. Signed-off-by: Reimar Döffinger reimar.doeffin...@gmx.de --- libavutil/dict.c | 9 +++-- libavutil/dict.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) doesnt apply Applying: dict.c: Free non-strduped av_dict_set arguments on error. fatal: sha1 information is lacking or useless (libavutil/dict.c). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge. Patch failed at 0001 dict.c: Free non-strduped av_dict_set arguments on error. Sorry, I messed this up at some point. Resent, with the missing patch which was the real reason for all this, and with order changed to make a bit more sense. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH 1/3] dict.c: Free non-strduped av_dict_set arguments on error.
Unfortunately this was not explicitly documented and thus might be very risky. But basically all uses I saw in FFmpeg had a memleak in these cases. Signed-off-by: Reimar Döffinger reimar.doeffin...@gmx.de --- libavutil/dict.c | 9 +++-- libavutil/dict.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libavutil/dict.c b/libavutil/dict.c index 0875b4d..66a0773 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -93,7 +93,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, if (tmp) m-elems = tmp; else -return AVERROR(ENOMEM); +goto err_out; } if (value) { if (flags AV_DICT_DONT_STRDUP_KEY) @@ -106,7 +106,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int len = strlen(oldval) + strlen(value) + 1; char *newval = av_mallocz(len); if (!newval) -return AVERROR(ENOMEM); +goto err_out; av_strlcat(newval, oldval, len); av_freep(oldval); av_strlcat(newval, value, len); @@ -121,6 +121,11 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, } return 0; + +err_out: +if (flags AV_DICT_DONT_STRDUP_KEY) av_free(key); +if (flags AV_DICT_DONT_STRDUP_VAL) av_free(value); +return AVERROR(ENOMEM); } int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, diff --git a/libavutil/dict.h b/libavutil/dict.h index 06f1621..5e319fe 100644 --- a/libavutil/dict.h +++ b/libavutil/dict.h @@ -115,6 +115,8 @@ int av_dict_count(const AVDictionary *m); /** * Set the given entry in *pm, overwriting an existing entry. * + * Note: On error non-av_strduped arguments will be freed. + * * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL * a dictionary struct is allocated and put in *pm. * @param key entry key to add to *pm (will be av_strduped depending on flags) -- 2.0.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH 1/3] dict.c: Free non-strduped av_dict_set arguments on error.
On Tue, Jul 29, 2014 at 09:26:48PM +0200, Reimar Döffinger wrote: Unfortunately this was not explicitly documented and thus might be very risky. But basically all uses I saw in FFmpeg had a memleak in these cases. Signed-off-by: Reimar Döffinger reimar.doeffin...@gmx.de --- libavutil/dict.c | 9 +++-- libavutil/dict.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) doesnt apply Applying: dict.c: Free non-strduped av_dict_set arguments on error. fatal: sha1 information is lacking or useless (libavutil/dict.c). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge. Patch failed at 0001 dict.c: Free non-strduped av_dict_set arguments on error. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel