glsl: Check calloc return value in link_intrastage_shaders()
authorJuha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Wed, 7 May 2014 13:20:12 +0000 (16:20 +0300)
committerTapani Pälli <tapani.palli@intel.com>
Tue, 23 Sep 2014 07:25:02 +0000 (10:25 +0300)
Check calloc return value while adding build-in functions.

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/glsl/linker.cpp

index 7689198b066db229d7330e122bd589ac834f2ecf..75e8b1696c5346a9b1a955c81341b229a89af918 100644 (file)
@@ -1714,12 +1714,19 @@ link_intrastage_shaders(void *mem_ctx,
        */
       gl_shader **linking_shaders = (gl_shader **)
          calloc(num_shaders + 1, sizeof(gl_shader *));
-      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);
+      ok = linking_shaders != NULL;
 
-      free(linking_shaders);
+      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);
+      } else {
+         _mesa_error_no_memory(__func__);
+      }
    } else {
       ok = link_function_calls(prog, linked, shader_list, num_shaders);
    }