Skip to content

Commit

Permalink
vd_lavc: fix device leak with copy-mode hwaccels
Browse files Browse the repository at this point in the history
Apparently this was broken by the "ctx->hwdec" check in the if condition
guarding the destroy call, and "ctx->hwdec = NULL;" was moved up
earlier, making this always dead code.

This should probably be refcounted or so, although that could make it
worse as well. For now, add a flag whether the device should be
destroyed.

Fixes #4735.
  • Loading branch information
wm4 committed Aug 9, 2017
1 parent 7397e8a commit de6d3f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions video/decode/lavc.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct lavc_ctx {

// Set by generic hwaccels.
struct mp_hwdec_ctx *hwdec_dev;
bool owns_hwdec_dev;

int hwdec_fmt;
int hwdec_w;
Expand Down
5 changes: 3 additions & 2 deletions video/decode/vd_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ static void init_avctx(struct dec_video *vd, const char *decoder,
ctx->hwdec_dev = hwdec_create_dev(vd, ctx->hwdec, false);
if (!ctx->hwdec_dev)
goto error;
ctx->owns_hwdec_dev = !!ctx->hwdec->create_dev;
if (ctx->hwdec_dev->restore_device)
ctx->hwdec_dev->restore_device(ctx->hwdec_dev);
if (!ctx->hwdec->set_hwframes) {
Expand Down Expand Up @@ -688,10 +689,10 @@ static void uninit_avctx(struct dec_video *vd)

avcodec_free_context(&ctx->avctx);

if (ctx->hwdec_dev && ctx->hwdec && ctx->hwdec->generic_hwaccel &&
ctx->hwdec_dev->destroy)
if (ctx->hwdec_dev && ctx->owns_hwdec_dev && ctx->hwdec_dev->destroy)
ctx->hwdec_dev->destroy(ctx->hwdec_dev);
ctx->hwdec_dev = NULL;
ctx->owns_hwdec_dev = false;

ctx->hwdec_failed = false;
ctx->hwdec_fail_count = 0;
Expand Down

0 comments on commit de6d3f8

Please sign in to comment.