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

Ian Romanick idr at freedesktop.org
Wed Feb 26 08:34:06 PST 2014


On 02/25/2014 06:41 AM, Juha-Pekka Heikkila wrote:
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>   src/mesa/tnl/t_vertex.c | 16 ++++++++++++++--
>   1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c
> index b3deac0..b3e70d3 100644
> --- a/src/mesa/tnl/t_vertex.c
> +++ b/src/mesa/tnl/t_vertex.c
> @@ -83,12 +83,24 @@ void _tnl_register_fastpath( struct tnl_clipspace *vtx,
>      struct tnl_clipspace_fastpath *fastpath = CALLOC_STRUCT(tnl_clipspace_fastpath);
>      GLuint i;
>
> +   if (fastpath == NULL) {
> +       GET_CURRENT_CONTEXT(ctx);
> +       _mesa_error(ctx, GL_OUT_OF_MEMORY, "out of memory");

Rather than repeating this in 394 places, this should either go in a 
helper function or a #define.  I seem to recall having already made that 
suggestion...  Also, have the paths through _mesa_error already been 
audited for safety in low memory situations?

> +      return;
> +   }
> +
>      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]));
> +   fastpath->attr = malloc(vtx->attr_count * sizeof(fastpath->attr[0]));
> +
> +   if (fastpath->attr == NULL) {
> +      FREE(fastpath);
> +      GET_CURRENT_CONTEXT(ctx);
> +      _mesa_error(ctx, GL_OUT_OF_MEMORY, "out of memory");
> +      return;
> +   }
>
>      for (i = 0; i < vtx->attr_count; i++) {
>         fastpath->attr[i].format = vtx->attr[i].format;



More information about the mesa-dev mailing list