glsl: Add missing null check in push_back()
authorJuha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Wed, 7 May 2014 09:38:07 +0000 (12:38 +0300)
committerVille Syrjälä <ville.syrjala@linux.intel.com>
Thu, 26 Jun 2014 12:37:14 +0000 (15:37 +0300)
Report memory error on realloc failure and don't leak any memory.

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/link_atomics.cpp

index d92cdb1170999520f810153a8024ce4d0280511c..fbe4e7364aebb1b4a8c6c0c7b39f479d90100853 100644 (file)
@@ -54,9 +54,18 @@ namespace {
 
       void push_back(unsigned id, ir_variable *var)
       {
-         counters = (active_atomic_counter *)
-            realloc(counters, sizeof(active_atomic_counter) * (num_counters + 1));
+         active_atomic_counter *new_counters;
 
+         new_counters = (active_atomic_counter *)
+            realloc(counters, sizeof(active_atomic_counter) *
+                    (num_counters + 1));
+
+         if (new_counters == NULL) {
+            _mesa_error_no_memory(__func__);
+            return;
+         }
+
+         counters = new_counters;
          counters[num_counters].id = id;
          counters[num_counters].var = var;
          num_counters++;