]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/apetag.c
avformat/apetag: Avoid allocation for small tags
[ffmpeg] / libavformat / apetag.c
index 8cb3f4a23af41db978b402560592f61e65b67b9a..4e19f49bf170fbc48cfff144781f03536b8be569 100644 (file)
@@ -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;
 }