[Mesa-dev] [PATCH 08/11] glsl: Check calloc return value in link_intrastage_shaders()

Ian Romanick idr at freedesktop.org
Fri Jun 20 18:16:48 PDT 2014


On 06/19/2014 05:24 AM, Juha-Pekka Heikkila wrote:
> Check calloc return value while adding build-in functions.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/glsl/linker.cpp | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
> index 247c828..1fc0213 100644
> --- a/src/glsl/linker.cpp
> +++ b/src/glsl/linker.cpp
> @@ -1593,6 +1593,12 @@ link_intrastage_shaders(void *mem_ctx,
>         */
>        gl_shader **linking_shaders = (gl_shader **)
>           calloc(num_shaders + 1, sizeof(gl_shader *));
> +
> +      if (linking_shaders == NULL) {
> +         _mesa_error_no_memory(__func__);
> +         ctx->Driver.DeleteShader(ctx, linked);
> +         return NULL;

Rather than duplicate the error path code, it seems like you could set
ok to false.  Something like:

      gl_shader **linking_shaders = (gl_shader **)
         calloc(num_shaders + 1, sizeof(gl_shader *));

      ok = linking_shader != NULL;
      if (ok) {
         memcpy(linking_shaders, shader_list, num_shaders * sizeof(gl_shader *));
         linking_shaders[num_shaders] = _mesa_glsl_get_builtin_function_shader();

         ok = link_function_calls(prog, linked, linking_shaders, num_shaders + 1);

         free(linking_shaders);
      }
        
> +      }
>        memcpy(linking_shaders, shader_list, num_shaders * sizeof(gl_shader *));
>        linking_shaders[num_shaders] = _mesa_glsl_get_builtin_function_shader();
>  



More information about the mesa-dev mailing list