From 30ad254d84047ffe3eba98943855b53a893390e2 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Fri, 9 Dec 2016 15:50:41 +0000 Subject: [PATCH] libdm: use correct region_id when cleaning up a failed filemap If we fail to create a region during dm_stats_create_regions_from_fd(), we must remove all regions that were created to do this to date. This needs to loop over the table of region_id values that were populated by _stats_create_file_regions() before the error. The code for this failure case in the out_remove branch incorrectly uses the table index as the region_id: for (--i; i != DM_STATS_REGION_NOT_PRESENT; i--) { if (!dm_stats_delete_region(dms, i)) log_error("Could not delete region " FMTu64 ".", i); } This causes the cleanup code to delete a completely unrelated set of regions (since the index here will always be nr_regions..0). Fix it to pass the actual region_id stored in regions[i] instead. --- libdm/libdm-stats.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index 390043377..438a1ed9a 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -4382,10 +4382,9 @@ static uint64_t *_stats_create_file_regions(struct dm_stats *dms, int fd, out_remove: /* clean up regions after create failure */ - for (--i; i != DM_STATS_REGION_NOT_PRESENT; i--) { - if (!dm_stats_delete_region(dms, i)) + for (--i; i != DM_STATS_REGION_NOT_PRESENT; i--) + if (!dm_stats_delete_region(dms, regions[i])) log_error("Could not delete region " FMTu64 ".", i); - } out: dm_pool_free(dms->mem, extents);