[Mesa-dev] [PATCH 2/5] Adding checks for NULL after CALLOC

Alex Deucher alexdeucher at gmail.com
Mon Jan 6 09:51:17 PST 2014


On Mon, Jan 6, 2014 at 10:15 AM, Bruno Jiménez <brunojimen at gmail.com> wrote:
> ---
>  src/gallium/drivers/r600/compute_memory_pool.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/gallium/drivers/r600/compute_memory_pool.c b/src/gallium/drivers/r600/compute_memory_pool.c
> index 7a7b057..62d1a5c 100644
> --- a/src/gallium/drivers/r600/compute_memory_pool.c
> +++ b/src/gallium/drivers/r600/compute_memory_pool.c
> @@ -50,6 +50,8 @@ struct compute_memory_pool* compute_memory_pool_new(
>  {
>         struct compute_memory_pool* pool = (struct compute_memory_pool*)
>                                 CALLOC(sizeof(struct compute_memory_pool), 1);
> +       if(pool == NULL)
> +               return NULL;

Space between if and paren.  e.g.,

if (pool == NULL)

>
>         COMPUTE_DBG(rscreen, "* compute_memory_pool_new()\n");
>
> @@ -65,6 +67,9 @@ static void compute_memory_pool_init(struct compute_memory_pool * pool,
>                 initial_size_in_dw);
>
>         pool->shadow = (uint32_t*)CALLOC(initial_size_in_dw, 4);
> +       if(pool->shadow == NULL)
> +               return;
> +

Same here.

>         pool->next_id = 1;
>         pool->size_in_dw = initial_size_in_dw;
>         pool->bo = (struct r600_resource*)r600_compute_buffer_alloc_vram(pool->screen,
> @@ -401,6 +406,9 @@ struct compute_memory_item* compute_memory_alloc(
>
>         new_item = (struct compute_memory_item *)
>                                 CALLOC(sizeof(struct compute_memory_item), 1);
> +       if(new_item == NULL)
> +               return NULL;
> +

Same here.

>         new_item->size_in_dw = size_in_dw;
>         new_item->start_in_dw = -1; /* mark pending */
>         new_item->id = pool->next_id++;
> --
> 1.8.5.2
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list