diff mbox series

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

Message ID 20200524002554.28064-3-andreas.rheinhardt@gmail.com
State Accepted
Commit 9fee37c56e60f9e24bf921188519a062de6185a1
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/img2dec.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index 40f3e3d499..ee7ceed08f 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -379,8 +379,7 @@  int ff_img_read_header(AVFormatContext *s1)
  * as a dictionary, so it can be used by filters like 'drawtext'.
  */
 static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt) {
-    uint8_t* metadata;
-    int metadata_len;
+    int metadata_len, ret;
     AVDictionary *d = NULL;
     char *packed_metadata = NULL;
 
@@ -391,13 +390,12 @@  static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt) {
     av_dict_free(&d);
     if (!packed_metadata)
         return AVERROR(ENOMEM);
-    if (!(metadata = av_packet_new_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, metadata_len))) {
+    ret = av_packet_add_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA,
+                                  packed_metadata, metadata_len);
+    if (ret < 0) {
         av_freep(&packed_metadata);
-        return AVERROR(ENOMEM);
+        return ret;
     }
-    memcpy(metadata, packed_metadata, metadata_len);
-    av_freep(&packed_metadata);
-
     return 0;
 }