avformat/oggdec: Avoid duplicating buffer when adding side-data master
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 23 May 2020 11:06:04 +0000 (13:06 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 28 May 2020 10:04:26 +0000 (12:04 +0200)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/oggdec.c
libavformat/oggparsevorbis.c

index 1a3acbb..b4ba00d 100644 (file)
@@ -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;
     }
 
index 246ba8f..0e8c25c 100644 (file)
@@ -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;
     }