diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2019-11-27 13:22:06 +0100 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2019-11-28 15:20:36 -0300 |
commit | 67ce9e0463e170179ece4abc33be716282a0202b (patch) | |
tree | e853a4dc520a406ee106b28877666bebc3648124 | |
parent | 163bb9ac0af495a5cb95441bdb5c02170440d28c (diff) | |
download | ffmpeg-67ce9e0463e170179ece4abc33be716282a0202b.tar.gz |
avformat/apetag: Avoid allocation for small tags
By using avio_get_dyn_buf() + ffio_free_dyn_buf() instead of
avio_close_dyn_buf() + av_free() one can avoid an allocation + copy for
small tags. Furthermore, it simplifies freeing.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r-- | libavformat/apetag.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/libavformat/apetag.c b/libavformat/apetag.c index 8cb3f4a23a..4e19f49bf1 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -186,11 +186,11 @@ int ff_ape_write_tag(AVFormatContext *s) { AVDictionaryEntry *e = NULL; int size, ret, count = 0; - AVIOContext *dyn_bc = NULL; - uint8_t *dyn_buf = NULL; + AVIOContext *dyn_bc; + uint8_t *dyn_buf; if ((ret = avio_open_dyn_buf(&dyn_bc)) < 0) - goto end; + return ret; ff_standardize_creation_time(s); while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) { @@ -211,7 +211,7 @@ int ff_ape_write_tag(AVFormatContext *s) if (!count) goto end; - size = avio_close_dyn_buf(dyn_bc, &dyn_buf); + size = avio_get_dyn_buf(dyn_bc, &dyn_buf); if (size <= 0) goto end; size += APE_TAG_FOOTER_BYTES; @@ -239,9 +239,7 @@ int ff_ape_write_tag(AVFormatContext *s) ffio_fill(s->pb, 0, 8); // reserved end: - if (dyn_bc && !dyn_buf) - avio_close_dyn_buf(dyn_bc, &dyn_buf); - av_freep(&dyn_buf); + ffio_free_dyn_buf(&dyn_bc); return ret; } |