From 28a9c9e573facb989736086383c2ba2ae882c4be Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Sun, 20 Dec 2020 15:44:20 -0800 Subject: [PATCH] d3d12: Fix memory leak if state is NULL. Fix defect reported by Coverity Scan. Resource leak (RESOURCE_LEAK) leaked_storage: Variable ss going out of scope leaks the storage it points to. Fixes: 2ea15cd661c ("d3d12: introduce d3d12 gallium driver") Signed-off-by: Vinson Lee Reviewed-by: Jesse Natalie Part-of: --- src/gallium/drivers/d3d12/d3d12_context.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp index cce9ffd6322..7f4c97e0b8b 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.cpp +++ b/src/gallium/drivers/d3d12/d3d12_context.cpp @@ -619,11 +619,12 @@ d3d12_create_sampler_state(struct pipe_context *pctx, { struct d3d12_context *ctx = d3d12_context(pctx); struct d3d12_screen *screen = d3d12_screen(pctx->screen); - struct d3d12_sampler_state *ss = CALLOC_STRUCT(d3d12_sampler_state); + struct d3d12_sampler_state *ss; D3D12_SAMPLER_DESC desc = {}; if (!state) return NULL; + ss = CALLOC_STRUCT(d3d12_sampler_state); ss->filter = (pipe_tex_filter)state->min_img_filter; ss->wrap_r = (pipe_tex_wrap)state->wrap_r; ss->wrap_s = (pipe_tex_wrap)state->wrap_s;