[FFmpeg-cvslog] copy_packet_data: fix memleak

Michael Niedermayer git at videolan.org
Mon Apr 29 03:28:31 CEST 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Apr 29 03:08:50 2013 +0200| [b691bc424f53f76c0d3aef36b4c7acc15b3dc3e9] | committer: Michael Niedermayer

copy_packet_data: fix memleak

This should fix gif fate memleaks

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b691bc424f53f76c0d3aef36b4c7acc15b3dc3e9
---

 libavcodec/avpacket.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 651036e..92f4fdf 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -180,7 +180,7 @@ do {                                         \
     } while (0)
 
 /* Makes duplicates of data, side_data, but does not copy any other fields */
-static int copy_packet_data(AVPacket *pkt, AVPacket *src)
+static int copy_packet_data(AVPacket *pkt, AVPacket *src, int dup)
 {
     pkt->data      = NULL;
     pkt->side_data = NULL;
@@ -196,8 +196,9 @@ static int copy_packet_data(AVPacket *pkt, AVPacket *src)
 #if FF_API_DESTRUCT_PACKET
     pkt->destruct = dummy_destruct_packet;
 #endif
-
-    if (pkt->side_data_elems) {
+    if (pkt->side_data_elems && dup)
+        pkt->side_data = src->side_data;
+    if (pkt->side_data_elems && !dup) {
         int i;
 
         DUP_DATA(pkt->side_data, src->side_data,
@@ -228,7 +229,7 @@ int av_dup_packet(AVPacket *pkt)
 #endif
         ) {
         tmp_pkt = *pkt;
-        return copy_packet_data(pkt, &tmp_pkt);
+        return copy_packet_data(pkt, &tmp_pkt, 1);
     }
     return 0;
 }
@@ -236,7 +237,7 @@ int av_dup_packet(AVPacket *pkt)
 int av_copy_packet(AVPacket *dst, AVPacket *src)
 {
     *dst = *src;
-    return copy_packet_data(dst, src);
+    return copy_packet_data(dst, src, 0);
 }
 
 void av_free_packet(AVPacket *pkt)



More information about the ffmpeg-cvslog mailing list