[Mesa-dev] [PATCH 5/6] nir: in insert_phi_nodes() check memory allocations succeeded.

Juha-Pekka Heikkila juhapekka.heikkila at gmail.com
Mon Jan 26 01:07:50 PST 2015


Report memory error and bail out on failure.

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
 src/glsl/nir/nir_to_ssa.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/glsl/nir/nir_to_ssa.c b/src/glsl/nir/nir_to_ssa.c
index 9c577fa..ccdbcf3 100644
--- a/src/glsl/nir/nir_to_ssa.c
+++ b/src/glsl/nir/nir_to_ssa.c
@@ -62,11 +62,13 @@ insert_trivial_phi(nir_register *reg, nir_block *block, void *mem_ctx)
 static void
 insert_phi_nodes(nir_function_impl *impl)
 {
-   void *mem_ctx = ralloc_parent(impl);
-
-   unsigned *work = calloc(impl->num_blocks, sizeof(unsigned));
-   unsigned *has_already = calloc(impl->num_blocks, sizeof(unsigned));
+   void *mem_ctx;
+   nir_block **W;
+   unsigned *work, *has_already;
 
+   mem_ctx = ralloc_parent(impl);
+   work = calloc(impl->num_blocks, sizeof(unsigned));
+   has_already = calloc(impl->num_blocks, sizeof(unsigned));
    /*
     * Since the work flags already prevent us from inserting a node that has
     * ever been inserted into W, we don't need to use a set to represent W.
@@ -75,7 +77,15 @@ insert_phi_nodes(nir_function_impl *impl)
     * function. So all we need to handle W is an array and a pointer to the
     * next element to be inserted and the next element to be removed.
     */
-   nir_block **W = malloc(impl->num_blocks * sizeof(nir_block *));
+   W = malloc(impl->num_blocks * sizeof(nir_block *));
+   if (!work || !has_already || !W) {
+      free(work);
+      free(has_already);
+      free(W);
+      _mesa_error_no_memory(__func__);
+      return;
+   }
+
    unsigned w_start, w_end;
 
    unsigned iter_count = 0;
-- 
1.8.5.1



More information about the mesa-dev mailing list