[FFmpeg-trac] #5027(avcodec:new): avcodec_free_context frees extradata
FFmpeg
trac at avcodec.org
Sun Nov 22 07:04:20 CET 2015
#5027: avcodec_free_context frees extradata
-----------------------------------+---------------------------------------
Reporter: jyavenard | Type: defect
Status: new | Priority: normal
Component: avcodec | Version: unspecified
Keywords: | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
-----------------------------------+---------------------------------------
According to the AVCodecContext specification:
AVCodecContext::extradata is "decoding: Set/allocated/freed by user. "
only for encoding is extradata managed by avcodec.
And avcodec_close does the right thing, and only free extradata field if
the AVCodecContext instantiated an encoder.
However, avcodec_free_context always free extradata if set:
{{{
void avcodec_free_context(AVCodecContext **pavctx)
{
AVCodecContext *avctx = *pavctx;
if (!avctx)
return;
avcodec_close(avctx);
av_freep(&avctx->extradata);
av_freep(&avctx->subtitle_header);
av_freep(&avctx->intra_matrix);
av_freep(&avctx->inter_matrix);
av_freep(&avctx->rc_override);
av_freep(pavctx);
}
}}}
This is incorrect, it assumes that the ownership of extradata is by
avcodec for either the decoder or the encoder.
Now the problem has been there for quite a while and it may be too late.
As such, either avcodec_free_context should be made obsolete and replaced
with avcodec_free_context2 which would do the right thing.
Or the documentation needs to be updated, and the ownership of extradata
now being by avcodec, this assumes that avcodec_close would also free
extradata.
--
Ticket URL: <https://trac.ffmpeg.org/ticket/5027>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list