]> git.sesse.net Git - ffmpeg/commit
avcodec/avcodec: Use avcodec_close() on avcodec_open2() failure
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
Wed, 28 Apr 2021 00:19:22 +0000 (02:19 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
Wed, 28 Apr 2021 00:19:22 +0000 (02:19 +0200)
commit9e13df3776da3a101e895e2840f6f23f5a6f74a0
treedcd731f776e589447b1944036acbb37db495e0fe
parent29f5c1e51b0d156f4650b96ab56c07727fe9a9b7
avcodec/avcodec: Use avcodec_close() on avcodec_open2() failure

Compared to the earlier behaviour the following changes:
a) AVCodecInternal.byte_buffer is freed.
b) The last_pkt_props FIFO is emptied before freeing it.
c) If set AVCodecContext.hwaccel is uninitialized and its private data
is freed; hw_frames_ctx and hw_device_ctx are also unreferenced.
d) coded_side_data is freed.
e) active_thread_type is reset.
a), b), d) should be no-ops as the buffer/fifo should be empty and
no coded_side_data should exist at any point of avcodec_open2().
e) is obviously not bad.
c) is in accordance with the documentation of hw_(frames|device)_ctx
which states that libacodec takes over ownership of these references.
At least in the case of VC-1 it is possible for the hw acceleration to
be set during init and in this case freeing it actually fixes a memleak.

avcodec_close() needed only minor adjustments to make it work with
a potentially not fully initialized codec.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
libavcodec/avcodec.c