diff mbox

[FFmpeg-devel,V2] avcodec/vaapi:free slice_buffers when decoding failed

Message ID 20180919020123.14736-1-linjie.fu@intel.com
State New
Headers show

Commit Message

Fu, Linjie Sept. 19, 2018, 2:01 a.m. UTC
If vaEndPicture failed in ff_vaapi_decode_issue, free
the pic->slice_buffer.

Fix the memory leak issue in ticket #7385

[V2] unit the return paths under the "exit" tag at
the end of the function.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
 libavcodec/vaapi_decode.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Mark Thompson Sept. 23, 2018, 4:47 p.m. UTC | #1
On 19/09/18 03:01, Linjie Fu wrote:
> If vaEndPicture failed in ff_vaapi_decode_issue, free
> the pic->slice_buffer.
> 
> Fix the memory leak issue in ticket #7385
> 
> [V2] unit the return paths under the "exit" tag at
> the end of the function.
> 
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
>  libavcodec/vaapi_decode.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)

Tested and applied.

Thanks,

- Mark
diff mbox

Patch

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index d0a6b5817d..3ee9c6be51 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -152,7 +152,7 @@  int ff_vaapi_decode_issue(AVCodecContext *avctx,
 {
     VAAPIDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
     VAStatus vas;
-    int err;
+    int err = 0;
 
     av_log(avctx, AV_LOG_DEBUG, "Decode to surface %#x.\n",
            pic->output_surface);
@@ -200,12 +200,7 @@  int ff_vaapi_decode_issue(AVCodecContext *avctx,
         AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS)
         ff_vaapi_decode_destroy_buffers(avctx, pic);
 
-    pic->nb_param_buffers = 0;
-    pic->nb_slices        = 0;
-    pic->slices_allocated = 0;
-    av_freep(&pic->slice_buffers);
-
-    return 0;
+    goto exit;
 
 fail_with_picture:
     vas = vaEndPicture(ctx->hwctx->display, ctx->va_context);
@@ -216,6 +211,12 @@  fail_with_picture:
 fail:
     ff_vaapi_decode_destroy_buffers(avctx, pic);
 fail_at_end:
+exit:
+    pic->nb_param_buffers = 0;
+    pic->nb_slices        = 0;
+    pic->slices_allocated = 0;
+    av_freep(&pic->slice_buffers);
+
     return err;
 }