avcodec/pthread_frame: Fix cleanup during init
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 11 Feb 2021 12:45:31 +0000 (13:45 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
Thu, 8 Apr 2021 09:52:52 +0000 (11:52 +0200)
commitaa8f8748caa15d99a77537cbd5bbec014a6630b8
tree5524b7e9e5fa8a202025dd6ec33d5af383a80fde
parent04012468459fb896e3a24202d7cc69b1cdda1db4
avcodec/pthread_frame: Fix cleanup during init

In case an error happened when setting up the child threads,
ff_frame_thread_init() would up until now call ff_frame_thread_free()
to clean up all threads set up so far, including the current, not
properly initialized one.
But a half-allocated context needs special handling which
ff_frame_thread_frame_free() doesn't provide.
Notably, if allocating the AVCodecInternal, the codec's private data
or setting the options fails, the codec's close function will be
called (if there is one); it will also be called if the codec's init
function fails, regardless of whether the FF_CODEC_CAP_INIT_CLEANUP
is set. This is not supported by all codecs; in ticket #9099 it led
to a crash.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit e9b66175793e5c2af19beefe8e143f6e4901b5df)
libavcodec/pthread_frame.c