From 26db1ed555f043abbce522e5c0dfb8fade70f6b0 Mon Sep 17 00:00:00 2001 From: Alex Deucher Date: Fri, 30 Jul 2010 15:46:05 -0400 Subject: [PATCH] r600: fix some possible memory leaks May fix bug 25483 NOTE: This is a candidate for the 7.8 branch. --- src/mesa/drivers/dri/r600/r700_assembler.c | 32 +++++++++++++++++++++------- src/mesa/drivers/dri/r600/r700_vertprog.c | 13 +++++++--- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/mesa/drivers/dri/r600/r700_assembler.c b/src/mesa/drivers/dri/r600/r700_assembler.c index 8f6cc1d..4e34036 100644 --- a/src/mesa/drivers/dri/r600/r700_assembler.c +++ b/src/mesa/drivers/dri/r600/r700_assembler.c @@ -997,6 +997,7 @@ GLboolean assemble_vfetch_instruction2(r700_AssemblerBase* pAsm, { if ( GL_FALSE == add_vfetch_instruction(pAsm, (R700VertexInstruction *)vfetch_instruction_ptr) ) { + free(vfetch_instruction_ptr); return GL_FALSE; } @@ -2332,8 +2333,8 @@ GLboolean check_vector(r700_AssemblerBase* pAsm, GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) { R700ALUInstruction * alu_instruction_ptr = NULL; - R700ALUInstructionHalfLiteral * alu_instruction_ptr_hl; - R700ALUInstructionFullLiteral * alu_instruction_ptr_fl; + R700ALUInstructionHalfLiteral * alu_instruction_ptr_hl = NULL; + R700ALUInstructionFullLiteral * alu_instruction_ptr_fl = NULL; GLuint number_of_scalar_operations; GLboolean is_single_scalar_operation; @@ -2419,15 +2420,21 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) { case 0: alu_instruction_ptr = (R700ALUInstruction*) CALLOC_STRUCT(R700ALUInstruction); + if (!alu_instruction_ptr) + goto fail; Init_R700ALUInstruction(alu_instruction_ptr); break; case 1: alu_instruction_ptr_hl = (R700ALUInstructionHalfLiteral*) CALLOC_STRUCT(R700ALUInstructionHalfLiteral); + if (!alu_instruction_ptr_hl) + goto fail; Init_R700ALUInstructionHalfLiteral(alu_instruction_ptr_hl, pAsm->C[0].f, pAsm->C[1].f); alu_instruction_ptr = (R700ALUInstruction*)alu_instruction_ptr_hl; break; case 2: alu_instruction_ptr_fl = (R700ALUInstructionFullLiteral*) CALLOC_STRUCT(R700ALUInstructionFullLiteral); + if (!alu_instruction_ptr_fl) + goto fail; Init_R700ALUInstructionFullLiteral(alu_instruction_ptr_fl,pAsm->C[0].f, pAsm->C[1].f, pAsm->C[2].f, pAsm->C[3].f); alu_instruction_ptr = (R700ALUInstruction*)alu_instruction_ptr_fl; break; @@ -2436,6 +2443,8 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) else { alu_instruction_ptr = (R700ALUInstruction*) CALLOC_STRUCT(R700ALUInstruction); + if (!alu_instruction_ptr) + goto fail; Init_R700ALUInstruction(alu_instruction_ptr); } @@ -2448,7 +2457,7 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) pcurrent_source, scalar_channel_index) ) { - return GL_FALSE; + goto fail; } if (uNumSrc > 1) @@ -2462,7 +2471,7 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) pcurrent_source, scalar_channel_index) ) { - return GL_FALSE; + goto fail; } } @@ -2500,7 +2509,7 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) else { radeon_error("Only temp destination registers supported for ALU dest regs.\n"); - return GL_FALSE; + goto fail; } alu_instruction_ptr->m_Word1.f.dst_rel = SQ_ABSOLUTE; //D.rtype @@ -2545,7 +2554,7 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) pcurrent_source, scalar_channel_index) ) { - return GL_FALSE; + goto fail; } } else @@ -2624,14 +2633,14 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) { if(GL_FALSE == check_scalar(pAsm, alu_instruction_ptr) ) { - return GL_FALSE; + goto fail; } } else { if(GL_FALSE == check_vector(pAsm, alu_instruction_ptr) ) { - return GL_FALSE; + goto fail; } } @@ -2639,6 +2648,13 @@ GLboolean assemble_alu_instruction(r700_AssemblerBase *pAsm) } return GL_TRUE; + +fail: + free(alu_instruction_ptr); + free(alu_instruction_ptr_hl); + free(alu_instruction_ptr_fl); + return GL_FALSE; + } GLboolean assemble_math_function(r700_AssemblerBase* pAsm, BITS opcode) diff --git a/src/mesa/drivers/dri/r600/r700_vertprog.c b/src/mesa/drivers/dri/r600/r700_vertprog.c index 137f300..29f59bc 100644 --- a/src/mesa/drivers/dri/r600/r700_vertprog.c +++ b/src/mesa/drivers/dri/r600/r700_vertprog.c @@ -335,7 +335,7 @@ struct r700_vertex_program* r700TranslateVertexShader(GLcontext *ctx, if(GL_FALSE == Find_Instruction_Dependencies_vp(vp, vp->mesa_program)) { - return NULL; + goto fail; } InitShaderProgram(&(vp->r700AsmCode)); @@ -353,17 +353,17 @@ struct r700_vertex_program* r700TranslateVertexShader(GLcontext *ctx, &(vp->mesa_program->Base.Instructions[0]), &(vp->r700AsmCode)) ) { - return NULL; + goto fail; } if(GL_FALSE == Process_Vertex_Exports(&(vp->r700AsmCode), vp->mesa_program->Base.OutputsWritten) ) { - return NULL; + goto fail; } if( GL_FALSE == RelocProgram(&(vp->r700AsmCode), &(vp->mesa_program->Base)) ) { - return GL_FALSE; + goto fail; } vp->r700Shader.nRegs = (vp->r700AsmCode.number_used_registers == 0) ? 0 @@ -374,6 +374,11 @@ struct r700_vertex_program* r700TranslateVertexShader(GLcontext *ctx, vp->translated = GL_TRUE; return vp; + +fail: + _mesa_reference_vertprog(ctx, &vp->mesa_program, NULL); + free(vp); + return NULL; } void r700SelectVertexShader(GLcontext *ctx) -- 1.7.1.1