From 47bfc799da61aadd60ef9cc5c4bf0651c519cc77 Mon Sep 17 00:00:00 2001 From: Axel Davy Date: Sun, 10 May 2020 20:12:56 +0200 Subject: [PATCH] gallium/util: Fix leak in the live shader cache MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When the nir backend is used, the create_shader call is supposed to release state->ir.nir. When the cache hits, create_shader is not called, thus state->ir.nir should be freed. There is nothing to be done for the TGSI case as the tokens release is done by the caller. This fixes a leak noticed in: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2931 Fixes: 4bb919b0b8b4ed6f6a7049c3f8d294b74b50e198 Signed-off-by: Axel Davy Reviewed-by: Marek Olšák Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/auxiliary/util/u_live_shader_cache.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/util/u_live_shader_cache.c b/src/gallium/auxiliary/util/u_live_shader_cache.c index a32c3748257..15f387b4931 100644 --- a/src/gallium/auxiliary/util/u_live_shader_cache.c +++ b/src/gallium/auxiliary/util/u_live_shader_cache.c @@ -129,8 +129,11 @@ util_live_shader_cache_get(struct pipe_context *ctx, *cache_hit = (shader != NULL); /* Return if the shader already exists. */ - if (shader) + if (shader) { + if (state->type == PIPE_SHADER_IR_NIR) + ralloc_free(state->ir.nir); return shader; + } /* The cache mutex is unlocked to allow multiple create_shader * invocations to run simultaneously. -- 2.30.2