avformat/tests/fifo_muxer: Fix memleak on error, fix API violation

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.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt
2021-03-19 01:31:31 +01:00
parent aff1d373b1
commit edcbb3e1b9

View File

@@ -41,18 +41,15 @@ typedef struct FailingMuxerPacketData {
static int prepare_packet(AVPacket *pkt, const FailingMuxerPacketData *pkt_data, int64_t pts) static int prepare_packet(AVPacket *pkt, const FailingMuxerPacketData *pkt_data, int64_t pts)
{ {
int ret; int ret = av_new_packet(pkt, sizeof(*pkt_data));
FailingMuxerPacketData *data = av_malloc(sizeof(*data)); if (ret < 0)
if (!data) { return ret;
return AVERROR(ENOMEM); memcpy(pkt->data, pkt_data, sizeof(*pkt_data));
}
memcpy(data, pkt_data, sizeof(FailingMuxerPacketData));
ret = av_packet_from_data(pkt, (uint8_t*) data, sizeof(*data));
pkt->pts = pkt->dts = pts; pkt->pts = pkt->dts = pts;
pkt->duration = 1; pkt->duration = 1;
return ret; return 0;
} }
static int initialize_fifo_tst_muxer_chain(AVFormatContext **oc, AVPacket **pkt) static int initialize_fifo_tst_muxer_chain(AVFormatContext **oc, AVPacket **pkt)