X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Fdict.c;h=c17ce7a3cbd0663e11ef3d5427eb01c580f2269f;hb=746095bc29817875ac89a7d4771f8a54895b3cbb;hp=aea89105412044b1ba5d0bf6cd5a055f1e730d25;hpb=8d7c4cc08238d06eb921bb0c6134a4475b0c689e;p=ffmpeg diff --git a/libavutil/dict.c b/libavutil/dict.c index aea89105412..c17ce7a3cbd 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -91,7 +91,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, AVDictionaryEntry *tmp = av_realloc(m->elems, (m->count + 1) * sizeof(*m->elems)); if (!tmp) - return AVERROR(ENOMEM); + goto err_out; m->elems = tmp; } if (value) { @@ -105,7 +105,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); @@ -120,6 +120,21 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, } return 0; + +err_out: + if (!m->count) { + av_free(m->elems); + av_freep(pm); + } + return AVERROR(ENOMEM); +} + +int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, + int flags) +{ + char valuestr[22]; + snprintf(valuestr, sizeof(valuestr), "%"PRId64, value); + return av_dict_set(pm, key, valuestr, flags); } static int parse_key_value_pair(AVDictionary **pm, const char **buf,