Mesa (master): softpipe: check for null pointers during context create/ destroy

Brian Paul brianp at kemper.freedesktop.org
Thu Jan 20 20:49:55 UTC 2011


Module: Mesa
Branch: master
Commit: 37233f1ee0213a224611788bbab38840ba9f8308
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=37233f1ee0213a224611788bbab38840ba9f8308

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 20 13:46:53 2011 -0700

softpipe: check for null pointers during context create/destroy

See http://bugs.freedesktop.org/show_bug.cgi?id=32309
Apparently, malloc() is failing during context creation.  Not
checking for nulls here led to crashes elsewhere.

---

 src/gallium/drivers/softpipe/sp_context.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c
index 2ee2181..fe54f92 100644
--- a/src/gallium/drivers/softpipe/sp_context.c
+++ b/src/gallium/drivers/softpipe/sp_context.c
@@ -91,10 +91,17 @@ softpipe_destroy( struct pipe_context *pipe )
    if (softpipe->draw)
       draw_destroy( softpipe->draw );
 
-   softpipe->quad.shade->destroy( softpipe->quad.shade );
-   softpipe->quad.depth_test->destroy( softpipe->quad.depth_test );
-   softpipe->quad.blend->destroy( softpipe->quad.blend );
-   softpipe->quad.pstipple->destroy( softpipe->quad.pstipple );
+   if (softpipe->quad.shade)
+      softpipe->quad.shade->destroy( softpipe->quad.shade );
+
+   if (softpipe->quad.depth_test)
+      softpipe->quad.depth_test->destroy( softpipe->quad.depth_test );
+
+   if (softpipe->quad.blend)
+      softpipe->quad.blend->destroy( softpipe->quad.blend );
+
+   if (softpipe->quad.pstipple)
+      softpipe->quad.pstipple->destroy( softpipe->quad.pstipple );
 
    for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
       sp_destroy_tile_cache(softpipe->cbuf_cache[i]);
@@ -262,13 +269,22 @@ softpipe_create_context( struct pipe_screen *screen,
       softpipe->cbuf_cache[i] = sp_create_tile_cache( &softpipe->pipe );
    softpipe->zsbuf_cache = sp_create_tile_cache( &softpipe->pipe );
 
-   for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
+   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
       softpipe->fragment_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe );
+      if (!softpipe->fragment_tex_cache[i])
+         goto fail;
+   }
+
    for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
       softpipe->vertex_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe );
+      if (!softpipe->vertex_tex_cache[i])
+         goto fail;
    }
+
    for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) {
       softpipe->geometry_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe );
+      if (!softpipe->geometry_tex_cache[i])
+         goto fail;
    }
 
    softpipe->fs_machine = tgsi_exec_machine_create();




More information about the mesa-commit mailing list