From: Michal Krol Date: Thu, 19 Nov 2009 11:52:58 +0000 (+0100) Subject: slang: Be more robust with memory in concat_shaders(). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f61865799defe6636ac893c7ddb510911e5bfa0c;p=mesa.git slang: Be more robust with memory in concat_shaders(). --- diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c index 0a2bc497803..ed27821a951 100644 --- a/src/mesa/shader/slang/slang_link.c +++ b/src/mesa/shader/slang/slang_link.c @@ -590,11 +590,16 @@ concat_shaders(struct gl_shader_program *shProg, GLenum shaderType) { struct gl_shader *newShader; const struct gl_shader *firstShader = NULL; - GLuint shaderLengths[100]; + GLuint *shaderLengths; GLchar *source; GLuint totalLen = 0, len = 0; GLuint i; + shaderLengths = (GLuint *)_mesa_malloc(shProg->NumShaders * sizeof(GLuint)); + if (!shaderLengths) { + return NULL; + } + /* compute total size of new shader source code */ for (i = 0; i < shProg->NumShaders; i++) { const struct gl_shader *shader = shProg->Shaders[i]; @@ -606,12 +611,16 @@ concat_shaders(struct gl_shader_program *shProg, GLenum shaderType) } } - if (totalLen == 0) + if (totalLen == 0) { + _mesa_free(shaderLengths); return NULL; + } source = (GLchar *) _mesa_malloc(totalLen + 1); - if (!source) + if (!source) { + _mesa_free(shaderLengths); return NULL; + } /* concatenate shaders */ for (i = 0; i < shProg->NumShaders; i++) { @@ -626,9 +635,16 @@ concat_shaders(struct gl_shader_program *shProg, GLenum shaderType) _mesa_printf("---NEW CONCATENATED SHADER---:\n%s\n------------\n", source); */ + _mesa_free(shaderLengths); + remove_extra_version_directives(source); newShader = CALLOC_STRUCT(gl_shader); + if (!newShader) { + _mesa_free(source); + return NULL; + } + newShader->Type = shaderType; newShader->Source = source; newShader->Pragmas = firstShader->Pragmas;