From a0e14505ec1260dfef631ad3f43711243a2b7e7c Mon Sep 17 00:00:00 2001 From: Shinji Suzuki Date: Sun, 2 Aug 2020 14:30:32 +0900 Subject: [PATCH] Avoid null pointer derefrence in grib_expression_free(). --- src/grib_expression.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/grib_expression.c b/src/grib_expression.c index 43dcde427..57801fac8 100644 --- a/src/grib_expression.c +++ b/src/grib_expression.c @@ -89,13 +89,15 @@ void grib_expression_print(grib_context* ctx, grib_expression* g, grib_handle* f void grib_expression_free(grib_context* ctx, grib_expression* g) { - grib_expression_class* c = g->cclass; - while (c) { - if (c->destroy) - c->destroy(ctx, g); - c = c->super ? *(c->super) : NULL; + if (g) { + grib_expression_class* c = g->cclass; + while (c) { + if (c->destroy) + c->destroy(ctx, g); + c = c->super ? *(c->super) : NULL; + } + grib_context_free_persistent(ctx, g); } - grib_context_free_persistent(ctx, g); } void grib_expression_add_dependency(grib_expression* e, grib_accessor* observer)