gallium/hud: check NULL return from u_upload_alloc
authorJulien Isorce <julien.isorce@gmail.com>
Fri, 10 Mar 2017 17:16:07 +0000 (17:16 +0000)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 13 Mar 2017 16:20:21 +0000 (17:20 +0100)
Fixes the following segmentation fault:

signal SIGSEGV: invalid address (fault address: 0x0)
 frame #0: 0x00007fffe718e117 radeonsi_dri.so hud_draw_background_quad hud_context.c:170
   167
   168     assert(hud->bg.num_vertices + 4 <= hud->bg.max_num_vertices);
   169
-> 170     vertices[num++] = (float) x1;
   171     vertices[num++] = (float) y1;
   172
   173     vertices[num++] = (float) x1;
(lldb) bt
  * frame #0: 0x00007fffe718e117 radeonsi_dri.so`hud_draw_background_quad
    frame #1: 0x00007fffe718f458 radeonsi_dri.so`hud_draw
    frame #2: 0x00007fffe712967f radeonsi_dri.so`dri_flush

Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/hud/hud_context.c

index c44f8c01a31fd404288c34c09833ce0116bd8abf..29ef9eee31c6a0308339a67db46093f7e9916765 100644 (file)
@@ -581,6 +581,10 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
                   hud->color_prims.buffer_size,
                   16, &hud->bg.vbuf.buffer_offset, &hud->bg.vbuf.buffer,
                   (void**)&hud->bg.vertices);
+   if (!hud->bg.vertices) {
+      goto out;
+   }
+
    pipe_resource_reference(&hud->whitelines.vbuf.buffer, hud->bg.vbuf.buffer);
    pipe_resource_reference(&hud->text.vbuf.buffer, hud->bg.vbuf.buffer);
    pipe_resource_reference(&hud->color_prims.vbuf.buffer, hud->bg.vbuf.buffer);
@@ -690,6 +694,7 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
          hud_pane_draw_colored_objects(hud, pane);
    }
 
+out:
    cso_restore_state(cso);
    cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);