Skip to content

Commit

Permalink
rtpdec: Forward the memory failure
Browse files Browse the repository at this point in the history
And avoid a memory leak.

Signed-off-by: Luca Barbato <[email protected]>
  • Loading branch information
lu-zero committed Sep 16, 2015
1 parent 1ec611a commit 22cc57d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libavformat/rtpdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ void ff_rtp_reset_packet_queue(RTPDemuxContext *s)
s->prev_ret = 0;
}

static void enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
static int enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
{
uint16_t seq = AV_RB16(buf + 2);
RTPPacket **cur = &s->queue, *packet;
Expand All @@ -699,14 +699,16 @@ static void enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)

packet = av_mallocz(sizeof(*packet));
if (!packet)
return;
return AVERROR(ENOMEM);
packet->recvtime = av_gettime_relative();
packet->seq = seq;
packet->len = len;
packet->buf = buf;
packet->next = *cur;
*cur = packet;
s->queue_len++;

return 0;
}

static int has_next_packet(RTPDemuxContext *s)
Expand Down Expand Up @@ -804,7 +806,9 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
return rv;
} else {
/* Still missing some packet, enqueue this one. */
enqueue_packet(s, buf, len);
rv = enqueue_packet(s, buf, len);
if (rv < 0)
return rv;
*bufptr = NULL;
/* Return the first enqueued packet if the queue is full,
* even if we're missing something */
Expand Down

0 comments on commit 22cc57d

Please sign in to comment.