[FFmpeg-cvslog] r25004 - trunk/libavformat/a64.c

Tobias Bindhammer tobias.bindhammer
Tue Aug 31 11:07:19 CEST 2010


Am 31.08.2010 10:45, schrieb Benoit Fouet:
> On Tue, 31 Aug 2010 09:15:11 +0200 (CEST) bindhammer wrote:
>> Author: bindhammer
>> Date: Tue Aug 31 09:15:11 2010
>> New Revision: 25004
>>
>> Log:
>> Solving memory leak and initialization problem with prev_pkt / pkt.
>>
>> Modified:
>>    trunk/libavformat/a64.c
>>
>> Modified: trunk/libavformat/a64.c
>> ==============================================================================
>> --- trunk/libavformat/a64.c	Tue Aug 31 09:14:47 2010	(r25003)
>> +++ trunk/libavformat/a64.c	Tue Aug 31 09:15:11 2010	(r25004)
>> @@ -125,8 +125,16 @@ static int a64_write_packet(struct AVFor
>>              }
>>              /* backup current packet for next turn */
>>              if(pkt->data) {
>> -                av_new_packet(&c->prev_pkt, pkt->size);
>> -                memcpy(c->prev_pkt.data, pkt->data, 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);
>> +                    c->prev_pkt.size = pkt->size;
>> +                } else {
>> +                    av_log(avctx, AV_LOG_ERROR, "Too less memory for prev_pkt.\n");
>> +                    return AVERROR(ENOMEM);
> 
> can that happen?
> If yes, maybe you should allocate another one in this case,
> desctructing the previous one.
> (BTW, the error message is not correct)

Actually the size can only shrink in the last packet yet. But i thought
i better have an error thrown in that case instead of strange things
happening, if anything changes in the encoder and make it necessary to
have varying packet sizes. In fact this could also be a "This should not
happen." error :-) But destructing and reallocating is also an option,
though yet never used.

Toby

-- 
Dipl. Ing. Tobias Bindhammer
Institut f?r Verteilte Systeme
Oberer Eselsberg          Phone: + 49 731/502-4235
Universit?t Ulm           Fax  : + 49 731/502-4142
D-89069 Ulm               mailto:tobias.bindhammer at uni-ulm.de
http://www-vs.informatik.uni-ulm.de/~bindhammer/



More information about the ffmpeg-cvslog mailing list