`last` points to fiemap::fm_extends[n], and if fiemap gets freed, we can
not reference any of its fieldis. so we could remember the check result before
freeing it.
Signed-off-by: Kefu Chai <kchai@redhat.com>
{
uint64_t i;
struct fiemap_extent *extent = NULL;
- struct fiemap_extent *last = NULL;
struct fiemap *fiemap = NULL;
int r = 0;
i = 0;
+ struct fiemap_extent *last = nullptr;
while (i < fiemap->fm_mapped_extents) {
struct fiemap_extent *next = extent + 1;
i++;
last = extent++;
}
+ const bool is_last = last->fe_flags & FIEMAP_EXTENT_LAST;
free(fiemap);
- if (!(last->fe_flags & FIEMAP_EXTENT_LAST)) {
+ if (!is_last) {
uint64_t xoffset = last->fe_logical + last->fe_length - offset;
offset = last->fe_logical + last->fe_length;
len -= xoffset;