avcodec/vaapi_encode: Fix segfault upon closing uninitialized encoder
Fixes ticket #9537.
Probably a regression since 2b32068916
.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
8a18db3ec6
commit
d1b47f3bfc
|
@ -2366,6 +2366,11 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
|
||||||
VAStatus vas;
|
VAStatus vas;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
ctx->va_config = VA_INVALID_ID;
|
||||||
|
ctx->va_context = VA_INVALID_ID;
|
||||||
|
|
||||||
|
/* If you add something that can fail above this av_frame_alloc(),
|
||||||
|
* modify ff_vaapi_encode_close() accordingly. */
|
||||||
ctx->frame = av_frame_alloc();
|
ctx->frame = av_frame_alloc();
|
||||||
if (!ctx->frame) {
|
if (!ctx->frame) {
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
@ -2377,9 +2382,6 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->va_config = VA_INVALID_ID;
|
|
||||||
ctx->va_context = VA_INVALID_ID;
|
|
||||||
|
|
||||||
ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
|
ctx->input_frames_ref = av_buffer_ref(avctx->hw_frames_ctx);
|
||||||
if (!ctx->input_frames_ref) {
|
if (!ctx->input_frames_ref) {
|
||||||
err = AVERROR(ENOMEM);
|
err = AVERROR(ENOMEM);
|
||||||
|
@ -2531,6 +2533,11 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
|
||||||
VAAPIEncodeContext *ctx = avctx->priv_data;
|
VAAPIEncodeContext *ctx = avctx->priv_data;
|
||||||
VAAPIEncodePicture *pic, *next;
|
VAAPIEncodePicture *pic, *next;
|
||||||
|
|
||||||
|
/* We check ctx->frame to know whether ff_vaapi_encode_init()
|
||||||
|
* has been called and va_config/va_context initialized. */
|
||||||
|
if (!ctx->frame)
|
||||||
|
return 0;
|
||||||
|
|
||||||
for (pic = ctx->pic_start; pic; pic = next) {
|
for (pic = ctx->pic_start; pic; pic = next) {
|
||||||
next = pic->next;
|
next = pic->next;
|
||||||
vaapi_encode_free(avctx, pic);
|
vaapi_encode_free(avctx, pic);
|
||||||
|
|
Loading…
Reference in New Issue