On Wed, Mar 12, 2014 at 2:11 PM, Juha-Pekka Heikkila
<juhapekka.heikk...@gmail.com> wrote:
> Check calloc return values in hash_table_insert() and
> hash_table_replace()
>
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikk...@gmail.com>
> ---
>  src/mesa/program/prog_hash_table.c | 23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
>
> diff --git a/src/mesa/program/prog_hash_table.c 
> b/src/mesa/program/prog_hash_table.c
> index f45ed46..617bdaa 100644
> --- a/src/mesa/program/prog_hash_table.c
> +++ b/src/mesa/program/prog_hash_table.c
> @@ -143,10 +143,15 @@ hash_table_insert(struct hash_table *ht, void *data, 
> const void *key)
>
>      node = calloc(1, sizeof(*node));
>
> -    node->data = data;
> -    node->key = key;
> +    if (node != NULL) {
> +       node->data = data;
> +       node->key = key;
>
> -    insert_at_head(& ht->buckets[bucket], & node->link);
> +       insert_at_head(& ht->buckets[bucket], & node->link);
> +    }
> +    else {
> +       _mesa_error_no_memory(__FUNCTION__);
> +    }
>  }

Let's just check calloc's return value, and if it's NULL call
_mesa_error_no_memory and return. That way we don't have to touch the
other code in the function. Same comment for the other hunk.
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to