nir: Check if u_vector_init() succeeds
authorTopi Pohjolainen <topi.pohjolainen@intel.com>
Thu, 5 Apr 2018 07:21:01 +0000 (10:21 +0300)
committerTopi Pohjolainen <topi.pohjolainen@intel.com>
Tue, 10 Apr 2018 22:49:56 +0000 (01:49 +0300)
However, it only fails when running out of memory. Now, if we
are about to check that, we should be consistent and check
the allocation of the worklist as well.

CID: 1433512
Fixes: edb18564c7 nir: Initial implementation of a nir_instr_worklist
Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Signed-off-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
src/compiler/nir/nir_worklist.h

index e37690876642b829ceafcbe5051e5f3ffef472ec..3fb391fceff08cf729e8f02c3f696dcacfc5b72c 100644 (file)
@@ -105,8 +105,15 @@ typedef struct {
 static inline nir_instr_worklist *
 nir_instr_worklist_create() {
    nir_instr_worklist *wl = malloc(sizeof(nir_instr_worklist));
-   u_vector_init(&wl->instr_vec, sizeof(struct nir_instr *),
-                 sizeof(struct nir_instr *) * 8);
+   if (!wl)
+      return NULL;
+
+   if (!u_vector_init(&wl->instr_vec, sizeof(struct nir_instr *),
+                      sizeof(struct nir_instr *) * 8)) {
+      free(wl);
+      return NULL;
+   }
+
    return wl;
 }