if (search && !found)
ret = 1;
+ while (!list_empty(all_uuids)) {
+ fs_devices = list_entry(all_uuids->next,
+ struct btrfs_fs_devices, list);
+ list_del(&fs_devices->list);
+ btrfs_close_devices(fs_devices);
+ }
out:
printf("%s\n", BTRFS_BUILD_VERSION);
free_seen_fsid();
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
{
struct btrfs_fs_devices *seed_devices;
- struct list_head *cur;
struct btrfs_device *device;
+
again:
- list_for_each(cur, &fs_devices->devices) {
- device = list_entry(cur, struct btrfs_device, dev_list);
+ while (!list_empty(&fs_devices->devices)) {
+ device = list_entry(fs_devices->devices.next,
+ struct btrfs_device, dev_list);
if (device->fd != -1) {
fsync(device->fd);
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
device->fd = -1;
}
device->writeable = 0;
+ list_del(&device->dev_list);
+ /* free the memory */
+ free(device->name);
+ free(device->label);
+ free(device);
}
seed_devices = fs_devices->seed;
goto again;
}
+ free(fs_devices);
return 0;
}