From 49377faccefc6bcccbc1683e76e5c9f769129196 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Fri, 16 Nov 2018 13:16:27 +0100 Subject: [PATCH] shader: Fix memory leaks reported by ASAN The following leaks can be triggered by running this test series: dEQP-GLES31.functional.tessellation_geometry_interaction.feedback.* Direct leak of 56 byte(s) in 8 object(s) allocated from: in __interceptor_strdup (/usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/ libasan.so+0x761c8) in emit_so_movs ../../../../virgl-gitlab/src/vrend_shader.c:1623 in iter_instruction ../../../../virgl-gitlab/src/vrend_shader.c:3873 in tgsi_iterate_shader ../../../../../../virgl-gitlab/src/gallium/ auxiliary/tgsi/tgsi_iterate.c:53 in vrend_convert_shader ../../../../virgl-gitlab/src/vrend_shader.c: 5131 ... Direct leak of 56 byte(s) in 7 object(s) allocated from: in __interceptor_calloc (/usr/lib64/gcc/x86_64-pc-linux-gnu/7.3.0/libasan.so+0xdba68) in vrend_convert_shader ../../../../virgl-gitlab/src/vrend_shader.c:5109 in vrend_shader_create ../../../../virgl-gitlab/src/vrend_renderer.c:2906 in vrend_shader_select ../../../../virgl-gitlab/src/vrend_renderer.c:2958 ... Closes: #55 Reviewed-by: Gurchetan Singh Signed-off-by: Gert Wollny Signed-off-by: Jakob Bornecrantz --- src/vrend_shader.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index e0b91f8..a467f3a 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -1612,13 +1612,16 @@ static int emit_so_movs(struct dump_ctx *ctx) writemask[0] = 0; if (!ctx->write_so_outputs[i]) { + if (ctx->so_names[i]) + free(ctx->so_names[i]); if (ctx->so->output[i].register_index > ctx->num_outputs) ctx->so_names[i] = NULL; else if (ctx->outputs[ctx->so->output[i].register_index].name == TGSI_SEMANTIC_CLIPVERTEX && ctx->has_clipvertex) { ctx->so_names[i] = strdup("clipv_tmp"); ctx->has_clipvertex_so = true; - } else + } else { ctx->so_names[i] = strdup(ctx->outputs[ctx->so->output[i].register_index].glsl_name); + } } else { char ntemp[8]; snprintf(ntemp, 8, "tfout%d", i); @@ -5189,6 +5192,15 @@ char *vrend_convert_shader(struct vrend_context *rctx, sinfo->gs_out_prim = ctx.gs_out_prim; sinfo->tes_prim = ctx.tes_prim_mode; sinfo->tes_point_mode = ctx.tes_point_mode; + + if (sinfo->so_names || ctx.so_names) { + if (sinfo->so_names) { + for (unsigned i = 0; i < sinfo->so_info.num_outputs; ++i) + free(sinfo->so_names[i]); + free(sinfo->so_names); + } + } + sinfo->so_names = ctx.so_names; sinfo->attrib_input_mask = ctx.attrib_input_mask; sinfo->sampler_arrays = ctx.sampler_arrays;