From 28533ac3f6d6cba685dc7dcc0d2be117754c7a6a Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 27 Jun 2018 13:39:27 +0200 Subject: [PATCH] isl_map_read_from_*: plug memory leak on error path In particular, when one or more disjuncts have been successfully parsed and an error occurs on the next disjunct, then the previous disjuncts did not get cleaned up. The leak was introduced in isl-0.19-18-gc584553093 (isl_input.c: obj_read: extract out obj_read_disjuncts, Mon Oct 16 14:36:03 2017 +0200). Signed-off-by: Sven Verdoolaege --- isl_input.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/isl_input.c b/isl_input.c index ea0fa711..950b40e8 100644 --- a/isl_input.c +++ b/isl_input.c @@ -2461,6 +2461,8 @@ error: static struct isl_obj obj_add(__isl_keep isl_stream *s, struct isl_obj obj1, struct isl_obj obj2) { + if (obj2.type == isl_obj_none || !obj2.v) + goto error; if (obj1.type == isl_obj_set && obj2.type == isl_obj_union_set) obj1 = to_union(s->ctx, obj1); if (obj1.type == isl_obj_union_set && obj2.type == isl_obj_set) @@ -2600,15 +2602,12 @@ static struct isl_obj obj_read_disjuncts(__isl_keep isl_stream *s, for (;;) { struct isl_obj o; o = obj_read_body(s, isl_map_copy(map), v); - if (o.type == isl_obj_none || !o.v) - return o; if (!obj.v) obj = o; - else { + else obj = obj_add(s, obj, o); - if (obj.type == isl_obj_none || !obj.v) - return obj; - } + if (obj.type == isl_obj_none || !obj.v) + return obj; if (!isl_stream_eat_if_available(s, ';')) break; if (isl_stream_next_token_is(s, '}')) -- 2.11.4.GIT