mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
Solving memory leak and initialization problem with prev_pkt / pkt.
Originally committed as revision 25004 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
d1cacdb8dd
commit
8731c86d03
@ -125,8 +125,16 @@ static int a64_write_packet(struct AVFormatContext *s, AVPacket *pkt)
|
|||||||
}
|
}
|
||||||
/* backup current packet for next turn */
|
/* backup current packet for next turn */
|
||||||
if(pkt->data) {
|
if(pkt->data) {
|
||||||
av_new_packet(&c->prev_pkt, pkt->size);
|
/* no backup packet yet? create one! */
|
||||||
|
if(!c->prev_pkt.data) av_new_packet(&c->prev_pkt, pkt->size);
|
||||||
|
/* we have a packet and data is big enough, reuse it */
|
||||||
|
if(c->prev_pkt.data && c->prev_pkt.size >= pkt->size) {
|
||||||
memcpy(c->prev_pkt.data, pkt->data, pkt->size);
|
memcpy(c->prev_pkt.data, pkt->data, pkt->size);
|
||||||
|
c->prev_pkt.size = pkt->size;
|
||||||
|
} else {
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "Too less memory for prev_pkt.\n");
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c->prev_frame_count = frame_count;
|
c->prev_frame_count = frame_count;
|
||||||
break;
|
break;
|
||||||
@ -145,9 +153,11 @@ static int a64_write_packet(struct AVFormatContext *s, AVPacket *pkt)
|
|||||||
static int a64_write_trailer(struct AVFormatContext *s)
|
static int a64_write_trailer(struct AVFormatContext *s)
|
||||||
{
|
{
|
||||||
A64MuxerContext *c = s->priv_data;
|
A64MuxerContext *c = s->priv_data;
|
||||||
AVPacket pkt;
|
AVPacket pkt = {0};
|
||||||
/* need to flush last packet? */
|
/* need to flush last packet? */
|
||||||
if(c->interleaved) a64_write_packet(s, &pkt);
|
if(c->interleaved) a64_write_packet(s, &pkt);
|
||||||
|
/* discard backed up packet */
|
||||||
|
if(c->prev_pkt.data) av_destruct_packet(&c->prev_pkt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user