diff mbox series

[FFmpeg-devel,4/4] avformat/oggdec: Avoid duplicating buffer when adding side-data

Message ID 20200524002554.28064-4-andreas.rheinhardt@gmail.com
State Accepted
Commit c0f01eaf12479b5d0160e1a8d10a73744fac5ab2
Headers show
Series [FFmpeg-devel,1/4] avformat/flvdec: Avoid duplicating extradata when adding side-data
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt May 24, 2020, 12:25 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/oggdec.c         | 12 +++++-------
 libavformat/oggparsevorbis.c |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 1a3acbb55e..b4ba00df61 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -877,14 +877,12 @@  retry:
     }
 
     if (os->new_metadata) {
-        uint8_t *side_data = av_packet_new_side_data(pkt,
-                                                     AV_PKT_DATA_METADATA_UPDATE,
-                                                     os->new_metadata_size);
-        if(!side_data)
-            return AVERROR(ENOMEM);
+        ret = av_packet_add_side_data(pkt, AV_PKT_DATA_METADATA_UPDATE,
+                                      os->new_metadata, os->new_metadata_size);
+        if (ret < 0)
+            return ret;
 
-        memcpy(side_data, os->new_metadata, os->new_metadata_size);
-        av_freep(&os->new_metadata);
+        os->new_metadata      = NULL;
         os->new_metadata_size = 0;
     }
 
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 27d2c686b6..f09d54488b 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -287,7 +287,7 @@  static int vorbis_update_metadata(AVFormatContext *s, int idx)
         os->new_metadata = av_packet_pack_dictionary(st->metadata, &os->new_metadata_size);
     /* Send an empty dictionary to indicate that metadata has been cleared. */
     } else {
-        os->new_metadata = av_malloc(1);
+        os->new_metadata = av_mallocz(1);
         os->new_metadata_size = 0;
     }