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>
pull/371/head
Andreas Rheinhardt 4 years ago
parent aff1d373b1
commit edcbb3e1b9
  1. 13
      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)

Loading…
Cancel
Save