isl_map.c: map_intersect_internal: properly plug memory leak on error path
authorSven Verdoolaege <skimo@kotnet.org>
Sun, 2 Dec 2012 09:57:46 +0000 (10:57 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 2 Dec 2012 11:23:44 +0000 (12:23 +0100)
The proposed fix in f85421c (isl_map.c: map_intersect_internal: plug memory
leak on error path, Fri Nov 30 18:10:08 2012 +0100) would only free "result",
but not "part".  Revert that commit and make sure both are freed.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_map.c

index b19be3c..28c35d2 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -2858,7 +2858,7 @@ static __isl_give isl_map *map_intersect_internal(__isl_take isl_map *map1,
        __isl_take isl_map *map2)
 {
        unsigned flags = 0;
-       isl_map *result = NULL;
+       isl_map *result;
        int i, j;
 
        if (!map1 || !map2)
@@ -2904,7 +2904,7 @@ static __isl_give isl_map *map_intersect_internal(__isl_take isl_map *map1,
                                    isl_basic_map_copy(map1->p[i]),
                                    isl_basic_map_copy(map2->p[j]));
                        if (isl_basic_map_is_empty(part) < 0)
-                               goto error;
+                               part = isl_basic_map_free(part);
                        result = isl_map_add_basic_map(result, part);
                        if (!result)
                                goto error;
@@ -2915,7 +2915,6 @@ static __isl_give isl_map *map_intersect_internal(__isl_take isl_map *map1,
 error:
        isl_map_free(map1);
        isl_map_free(map2);
-       isl_map_free(result);
        return NULL;
 }