diff mbox series

[FFmpeg-devel,2/4] avformat/tests/fifo_muxer: Fix memleak on error, fix API violation

Message ID 20210319005244.1737816-2-andreas.rheinhardt@gmail.com
State Accepted
Commit edcbb3e1b91b53b6fcd641a7f40bd707c090e0a7
Headers show
Series [FFmpeg-devel,1/4] avformat/tests/fifo_muxer: Fix leak of AVPacket on error
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 19, 2021, 12:52 a.m. UTC
The test program for the FIFO muxer allocates a buffer without padding
and wraps it into a packet via av_packet_from_data(). This is an API
violation. Furthermore, said buffer leaks in case av_packet_from_data()
fails. Fix both of these issues by using av_new_packet() instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/tests/fifo_muxer.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/tests/fifo_muxer.c b/libavformat/tests/fifo_muxer.c
index e8970259c4..227c3d0210 100644
--- a/libavformat/tests/fifo_muxer.c
+++ b/libavformat/tests/fifo_muxer.c
@@ -41,18 +41,15 @@  typedef struct FailingMuxerPacketData {
 
 static int prepare_packet(AVPacket *pkt, const FailingMuxerPacketData *pkt_data, int64_t pts)
 {
-    int ret;
-    FailingMuxerPacketData *data = av_malloc(sizeof(*data));
-    if (!data) {
-        return AVERROR(ENOMEM);
-    }
-    memcpy(data, pkt_data, sizeof(FailingMuxerPacketData));
-    ret = av_packet_from_data(pkt, (uint8_t*) data, sizeof(*data));
+    int ret = av_new_packet(pkt, sizeof(*pkt_data));
+    if (ret < 0)
+        return ret;
+    memcpy(pkt->data, pkt_data, sizeof(*pkt_data));
 
     pkt->pts = pkt->dts = pts;
     pkt->duration = 1;
 
-    return ret;
+    return 0;
 }
 
 static int initialize_fifo_tst_muxer_chain(AVFormatContext **oc, AVPacket **pkt)