[vlc-devel] [PATCH] demux: avformat: handle AV_PKT_DATA_NEW_EXTRADATA

Steve Lhomme robux4 at ycbcr.xyz
Mon Jan 4 10:07:44 UTC 2021


On 2021-01-04 10:25, "zhilizhao(赵志立)" wrote:
>>> @@ -821,6 +828,24 @@ static int Demux( demux_t *p_demux )
>>>           av_packet_unref( &pkt );
>>>           return 1;
>>>       }
>>> +
>>> +    // handle extra data change, this can happen for FLV
>>> +    int side_data_size;
>>> +    uint8_t *side_data = av_packet_get_side_data( &pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_data_size );
>>> +    if( side_data != NULL && side_data_size > 0 ) {
>>> +        msg_Warn( p_demux, "New extra data found, seek may not work as expected" );
>>> +        void *p_extra = realloc( p_track->es_format.p_extra, side_data_size );
>>> +        if( p_extra == NULL )
>>> +        {
>>> +            av_packet_unref( &pkt );
>>> +            return 0;
>>> +        }
>>> +        p_track->es_format.p_extra = p_extra;
>>
>> Missing free of the previous version.
> 
> There is memory leaks here since es_format will be cleaned during CloseDemux().
> Free extra data at here and the following error case will make the code a litter cumbersome.
> Is there something I’m missing?

It's leaking the p_extra data that were there until you force it to a 
new pointer. Yes, the last one will be released on close, but everything 
in between is lost here.



More information about the vlc-devel mailing list