diff mbox series

[FFmpeg-devel] avutil/hwcontext_qsv: register free function for device_derive

Message ID 20230616072723.1885-1-tong1.wu@intel.com
State New
Headers show
Series [FFmpeg-devel] avutil/hwcontext_qsv: register free function for device_derive | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Wu, Tong1 June 16, 2023, 7:27 a.m. UTC
When qsv device is created by device_derive, the ctx->free function is
not registered, causing potential memory leak because of not properly
closing the MFX session.

Signed-off-by: Tong Wu <tong1.wu@intel.com>
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavutil/hwcontext_qsv.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Xiang, Haihao June 19, 2023, 3:52 a.m. UTC | #1
On Vr, 2023-06-16 at 15:27 +0800, Tong Wu wrote:
> When qsv device is created by device_derive, the ctx->free function is
> not registered, causing potential memory leak because of not properly
> closing the MFX session.
> 
> Signed-off-by: Tong Wu <tong1.wu@intel.com>
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  libavutil/hwcontext_qsv.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 4ed4242ddf..713dc90ffd 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -2094,6 +2094,9 @@ static int qsv_device_derive(AVHWDeviceContext *ctx,
>                               AVDictionary *opts, int flags)
>  {
>      mfxIMPL impl;
> +
> +    ctx->free = qsv_device_free;

ctx->user_opaque is NULL, which might cause segmentation fault in
qsv_device_free().

Thanks
Haihao

> +    
>      impl = choose_implementation("hw_any", child_device_ctx->type);
>      return qsv_device_derive_from_child(ctx, impl,
>                                          child_device_ctx, flags);
diff mbox series

Patch

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 4ed4242ddf..713dc90ffd 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -2094,6 +2094,9 @@  static int qsv_device_derive(AVHWDeviceContext *ctx,
                              AVDictionary *opts, int flags)
 {
     mfxIMPL impl;
+
+    ctx->free = qsv_device_free;
+    
     impl = choose_implementation("hw_any", child_device_ctx->type);
     return qsv_device_derive_from_child(ctx, impl,
                                         child_device_ctx, flags);