Skip to content

Commit d6aefb5

Browse files
Patrick Lerda1ace
Patrick Lerda
authored andcommitted
r300: fix memory leaks when register allocation fails
For instance, this issue is triggered with "piglit/bin/ext_framebuffer_multisample-accuracy all_samples color depthstencil -auto -fbo": Direct leak of 1160 byte(s) in 1 object(s) allocated from: #0 0x7fbe8897d7ef in __interceptor_malloc (/usr/lib64/libasan.so.6+0xb17ef) #1 0x7fbe7e7abfcc in rc_constants_copy ../src/gallium/drivers/r300/compiler/radeon_code.c:47 #2 0x7fbe7e7ec902 in r3xx_compile_fragment_program ../src/gallium/drivers/r300/compiler/r3xx_fragprog.c:174 #3 0x7fbe7e7e1b22 in r300_translate_fragment_shader ../src/gallium/drivers/r300/r300_fs.c:516 #4 0x7fbe7e7e6373 in r300_pick_fragment_shader ../src/gallium/drivers/r300/r300_fs.c:591 #5 0x7fbe7e75456e in r300_create_fs_state ../src/gallium/drivers/r300/r300_state.c:1073 #6 0x7fbe7cd2ebe5 in st_create_fp_variant ../src/mesa/state_tracker/st_program.c:1070 #7 0x7fbe7cd374b5 in st_get_fp_variant ../src/mesa/state_tracker/st_program.c:1116 #8 0x7fbe7cd38273 in st_precompile_shader_variant ../src/mesa/state_tracker/st_program.c:1281 #9 0x7fbe7cd38273 in st_finalize_program ../src/mesa/state_tracker/st_program.c:1345 #10 0x7fbe7d798ca8 in st_link_glsl_to_nir ../src/mesa/state_tracker/st_glsl_to_nir.cpp:724 #11 0x7fbe7d798ca8 in st_link_shader ../src/mesa/state_tracker/st_glsl_to_nir.cpp:952 #12 0x7fbe7d6790d5 in link_program ../src/mesa/main/shaderapi.c:1336 #13 0x7fbe7d6790d5 in link_program_error ../src/mesa/main/shaderapi.c:1447 ... SUMMARY: AddressSanitizer: 2528456 byte(s) leaked in 1057 allocation(s). Fixes: 54f6e72 ("r300: better register allocator for vertex shaders") Signed-off-by: Patrick Lerda <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27792> (cherry picked from commit 4d00edd)
1 parent e94f1fc commit d6aefb5

File tree

4 files changed

+4
-1
lines changed

4 files changed

+4
-1
lines changed

.pick_status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@
16841684
"description": "r300: fix memory leaks when register allocation fails",
16851685
"nominated": true,
16861686
"nomination_type": 1,
1687-
"resolution": 0,
1687+
"resolution": 1,
16881688
"main_sha": null,
16891689
"because_sha": "54f6e72b27154219be237690453bb9c3b57cd3ec",
16901690
"notes": null

src/gallium/drivers/r300/compiler/r3xx_vertprog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ static void allocate_temporary_registers(struct radeon_compiler *c, void *user)
689689

690690
if (!ra_allocate(graph)) {
691691
rc_error(c, "Ran out of hardware temporaries\n");
692+
ralloc_free(graph);
692693
return;
693694
}
694695

src/gallium/drivers/r300/compiler/radeon_pair_regalloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ static void do_advanced_regalloc(struct regalloc_state * s)
357357

358358
if (!ra_allocate(graph)) {
359359
rc_error(s->C, "Ran out of hardware temporaries\n");
360+
ralloc_free(graph);
360361
return;
361362
}
362363

src/gallium/drivers/r300/r300_fs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ static void r300_translate_fragment_shader(
525525
abort();
526526
}
527527

528+
free(compiler.code->constants.Constants);
528529
rc_destroy(&compiler.Base);
529530
r300_dummy_fragment_shader(r300, shader);
530531
return;

0 commit comments

Comments
 (0)