diff mbox series

[FFmpeg-devel,7/8] avfilter/vf_thumbnail_cuda: Fix segfaults on uninit

Message ID AM7PR03MB6660E9011DA8CF07D25E938A8FAF9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 06045f4b1da1cbfa3446beef6797fb983a7dada5
Headers show
Series [FFmpeg-devel,1/8] avfilter/tests/filtfmts: Replace macro by ordinary function | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Oct. 5, 2021, 8:53 p.m. UTC
Uninit crashed if an array containing frames could not be allocated
or config_props() has never been called.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/vf_thumbnail_cuda.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/libavfilter/vf_thumbnail_cuda.c b/libavfilter/vf_thumbnail_cuda.c
index 491542c60a..7c86203227 100644
--- a/libavfilter/vf_thumbnail_cuda.c
+++ b/libavfilter/vf_thumbnail_cuda.c
@@ -306,6 +306,8 @@  static av_cold void uninit(AVFilterContext *ctx)
 {
     int i;
     ThumbnailCudaContext *s = ctx->priv;
+
+    if (s->hwctx) {
     CudaFunctions *cu = s->hwctx->internal->cuda_dl;
 
     if (s->data) {
@@ -317,10 +319,13 @@  static av_cold void uninit(AVFilterContext *ctx)
         CHECK_CU(cu->cuModuleUnload(s->cu_module));
         s->cu_module = NULL;
     }
+    }
 
+    if (s->frames) {
     for (i = 0; i < s->n_frames && s->frames[i].buf; i++)
         av_frame_free(&s->frames[i].buf);
     av_freep(&s->frames);
+    }
 }
 
 static int request_frame(AVFilterLink *link)