[Mesa-dev] [PATCH 07/11] glsl: Add missing null check in push_back()

Ian Romanick idr at freedesktop.org
Fri Jun 20 16:53:59 PDT 2014


Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 06/19/2014 05:24 AM, Juha-Pekka Heikkila wrote:
> Report memory error on realloc failure and don't leak any memory.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/glsl/link_atomics.cpp | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/src/glsl/link_atomics.cpp b/src/glsl/link_atomics.cpp
> index d92cdb1..fbe4e73 100644
> --- a/src/glsl/link_atomics.cpp
> +++ b/src/glsl/link_atomics.cpp
> @@ -54,9 +54,18 @@ namespace {
>  
>        void push_back(unsigned id, ir_variable *var)
>        {
> -         counters = (active_atomic_counter *)
> -            realloc(counters, sizeof(active_atomic_counter) * (num_counters + 1));
> +         active_atomic_counter *new_counters;
>  
> +         new_counters = (active_atomic_counter *)
> +            realloc(counters, sizeof(active_atomic_counter) *
> +                    (num_counters + 1));
> +
> +         if (new_counters == NULL) {
> +            _mesa_error_no_memory(__func__);
> +            return;
> +         }
> +
> +         counters = new_counters;
>           counters[num_counters].id = id;
>           counters[num_counters].var = var;
>           num_counters++;
> 



More information about the mesa-dev mailing list