diff --git a/tools/grib_options.c b/tools/grib_options.c index 299b376a0..195b7f450 100644 --- a/tools/grib_options.c +++ b/tools/grib_options.c @@ -434,10 +434,12 @@ char* grib_options_get_args(char* id) sprintf(err, "%s%c\n", msg, *id); for (i = 0; i < grib_options_count; i++) { if (!strcmp(id, grib_options[i].id)) { - if (grib_options[i].args != NULL) + if (grib_options[i].args != NULL) { + free(err); return grib_options[i].args; - else + } else { break; + } } } for (i = 0; i < grib_options_help_count; i++) { diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index 379fc24f1..d400ff095 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -1125,8 +1125,10 @@ static request* fieldset_to_request(fieldset* fs) int i; request* r = empty_request("GRIB"); - if (!fs) + if (!fs) { + free_one_request(r); return 0; + } for (i = 0; i < fs->count; i++) { request* s = field_to_request(fs->fields[i]); @@ -2423,10 +2425,10 @@ static int compute_scale(dataset_t* subset) } else { for (j = 0; j < len; ++j) { - if (vals[j] > max) - max = vals[j]; - if (vals[j] < min) - min = vals[j]; + if (vals) { + if (vals[j] > max) max = vals[j]; + if (vals[j] < min) min = vals[j]; + } } } /* g->purge_header = TRUE; */ @@ -3268,8 +3270,10 @@ static int fill_netcdf_dimensions(hypercube* h, fieldset* fs, int ncid) int* values = (int*)grib_context_malloc(ctx, sizeof(int) * n); const char* lowaxis = (axis); - if (!values) + if (!values) { grib_context_log(ctx, GRIB_LOG_ERROR, "fill_netcdf_dimensions: cannot allocate %ld bytes", sizeof(int) * n); + exit(1); + } if (strcmp("levelist", axis) == 0) lowaxis = "level";