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 <gurchetansingh@chromium.org>
Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Signed-off-by: Jakob Bornecrantz <jakob@collabora.com>
macos/master
Gert Wollny 6 years ago committed by Jakob Bornecrantz
parent 09bae9b23a
commit 49377facce
  1. 14
      src/vrend_shader.c

@ -1612,13 +1612,16 @@ static int emit_so_movs(struct dump_ctx *ctx)
writemask[0] = 0; writemask[0] = 0;
if (!ctx->write_so_outputs[i]) { 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) if (ctx->so->output[i].register_index > ctx->num_outputs)
ctx->so_names[i] = NULL; ctx->so_names[i] = NULL;
else if (ctx->outputs[ctx->so->output[i].register_index].name == TGSI_SEMANTIC_CLIPVERTEX && ctx->has_clipvertex) { 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->so_names[i] = strdup("clipv_tmp");
ctx->has_clipvertex_so = true; ctx->has_clipvertex_so = true;
} else } else {
ctx->so_names[i] = strdup(ctx->outputs[ctx->so->output[i].register_index].glsl_name); ctx->so_names[i] = strdup(ctx->outputs[ctx->so->output[i].register_index].glsl_name);
}
} else { } else {
char ntemp[8]; char ntemp[8];
snprintf(ntemp, 8, "tfout%d", i); 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->gs_out_prim = ctx.gs_out_prim;
sinfo->tes_prim = ctx.tes_prim_mode; sinfo->tes_prim = ctx.tes_prim_mode;
sinfo->tes_point_mode = ctx.tes_point_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->so_names = ctx.so_names;
sinfo->attrib_input_mask = ctx.attrib_input_mask; sinfo->attrib_input_mask = ctx.attrib_input_mask;
sinfo->sampler_arrays = ctx.sampler_arrays; sinfo->sampler_arrays = ctx.sampler_arrays;

Loading…
Cancel
Save