[Mesa-dev] [PATCH 10/10] mesa: add missing null checks in _tnl_register_fastpath()

Juha-Pekka Heikkila juhapekka.heikkila at gmail.com
Mon Feb 17 08:21:33 PST 2014


Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
 src/mesa/tnl/t_vertex.c | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c
index b3deac0..a122334 100644
--- a/src/mesa/tnl/t_vertex.c
+++ b/src/mesa/tnl/t_vertex.c
@@ -81,24 +81,31 @@ void _tnl_register_fastpath( struct tnl_clipspace *vtx,
 			     GLboolean match_strides )
 {
    struct tnl_clipspace_fastpath *fastpath = CALLOC_STRUCT(tnl_clipspace_fastpath);
-   GLuint i;
-
-   fastpath->vertex_size = vtx->vertex_size;
-   fastpath->attr_count = vtx->attr_count;
-   fastpath->match_strides = match_strides;
-   fastpath->func = vtx->emit;
-   fastpath->attr =
-      malloc(vtx->attr_count * sizeof(fastpath->attr[0]));
-
-   for (i = 0; i < vtx->attr_count; i++) {
-      fastpath->attr[i].format = vtx->attr[i].format;
-      fastpath->attr[i].stride = vtx->attr[i].inputstride;
-      fastpath->attr[i].size = vtx->attr[i].inputsize;
-      fastpath->attr[i].offset = vtx->attr[i].vertoffset;
-   }
 
-   fastpath->next = vtx->fastpath;
-   vtx->fastpath = fastpath;
+   if (fastpath != NULL) {
+      GLuint i;
+
+      fastpath->vertex_size = vtx->vertex_size;
+      fastpath->attr_count = vtx->attr_count;
+      fastpath->match_strides = match_strides;
+      fastpath->func = vtx->emit;
+      fastpath->attr = malloc(vtx->attr_count * sizeof(fastpath->attr[0]));
+
+      if (fastpath->attr == NULL) {
+         FREE(fastpath);
+         return;
+      }
+
+      for (i = 0; i < vtx->attr_count; i++) {
+         fastpath->attr[i].format = vtx->attr[i].format;
+         fastpath->attr[i].stride = vtx->attr[i].inputstride;
+         fastpath->attr[i].size = vtx->attr[i].inputsize;
+         fastpath->attr[i].offset = vtx->attr[i].vertoffset;
+      }
+
+      fastpath->next = vtx->fastpath;
+      vtx->fastpath = fastpath;
+   }
 }
 
 
-- 
1.8.1.2



More information about the mesa-dev mailing list