isl_hmap_map_basic_set_set: avoid memory leak on error path
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 5 Jun 2013 08:04:47 +0000 (10:04 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 5 Jun 2013 08:11:04 +0000 (10:11 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_hmap_map_basic_set.c

index b303516..09f7f60 100644 (file)
@@ -78,7 +78,7 @@ int isl_hmap_map_basic_set_set(isl_ctx *ctx,
        entry = isl_hash_table_find(ctx, &hmap->table, hash, &has_key, key, 1);
 
        if (!entry)
-               return -1;
+               goto error;
 
        if (entry->data) {
                pair = entry->data;
@@ -89,14 +89,15 @@ int isl_hmap_map_basic_set_set(isl_ctx *ctx,
        }
 
        pair = isl_alloc_type(ctx, struct isl_map_basic_set_pair);
-       if (!pair) {
-               isl_map_free(key);
-               isl_basic_set_free(val);
-               return -1;
-       }
+       if (!pair)
+               goto error;
 
        entry->data = pair;
        pair->key = key;
        pair->val = val;
        return 0;
+error:
+       isl_map_free(key);
+       isl_basic_set_free(val);
+       return -1;
 }