From c5b15632e7fab51e1aa6e474f80579eb918c21c4 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 2 Feb 2017 18:29:06 +0000 Subject: [PATCH] ECC-425: grib_to_netcdf crash when running out of memory --- tools/grib_to_netcdf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index d90abee53..4af844313 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -1641,7 +1641,7 @@ static hypercube *new_hypercube(const request *r) int total = 0, count = 0; int n = 0; const char *val = 0; - + Assert(h); h->r = clone_one_request(r); h->cube = empty_request("CUBE"); @@ -1746,8 +1746,10 @@ static hypercube *new_hypercube_from_mars_request(const request *r) } n = count_values(s.c->cube, "axis"); - if(n) + if(n) { s.c->compare = (namecmp*)calloc(sizeof(namecmp), n); + Assert(s.c->compare); + } for(i = 0; i < n; i++) s.c->compare[i] = comparator(get_value(s.c->cube, "axis", i)); @@ -1771,8 +1773,10 @@ static hypercube *new_simple_hypercube_from_mars_request(const request *r) free_one_request(s.r); n = count_values(s.c->cube, "axis"); - if(n) + if(n) { s.c->compare = (namecmp*)calloc(sizeof(namecmp), n); + Assert(s.c->compare); + } for(i = 0; i < n; i++) s.c->compare[i] = comparator(get_value(s.c->cube, "axis", i));