forked from Mirrors/btrfs-progs
btrfs-progs: Fix a memleak in btrfs_scan_one_device.
Valgrind reports memleak in btrfs_scan_one_device() about allocating btrfs_device but on btrfs_close_devices() they are not reclaimed. Although not a bug since after btrfs_close_devices() btrfs will exit so memory will be reclaimed by system anyway, it's better to fix it anyway. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>master
parent
64200e4453
commit
9d57509e99
|
@ -656,6 +656,12 @@ devs_only:
|
||||||
if (search && !found)
|
if (search && !found)
|
||||||
ret = 1;
|
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:
|
out:
|
||||||
printf("%s\n", BTRFS_BUILD_VERSION);
|
printf("%s\n", BTRFS_BUILD_VERSION);
|
||||||
free_seen_fsid();
|
free_seen_fsid();
|
||||||
|
|
13
volumes.c
13
volumes.c
|
@ -160,11 +160,12 @@ static int device_list_add(const char *path,
|
||||||
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
|
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
|
||||||
{
|
{
|
||||||
struct btrfs_fs_devices *seed_devices;
|
struct btrfs_fs_devices *seed_devices;
|
||||||
struct list_head *cur;
|
|
||||||
struct btrfs_device *device;
|
struct btrfs_device *device;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
list_for_each(cur, &fs_devices->devices) {
|
while (!list_empty(&fs_devices->devices)) {
|
||||||
device = list_entry(cur, struct btrfs_device, dev_list);
|
device = list_entry(fs_devices->devices.next,
|
||||||
|
struct btrfs_device, dev_list);
|
||||||
if (device->fd != -1) {
|
if (device->fd != -1) {
|
||||||
fsync(device->fd);
|
fsync(device->fd);
|
||||||
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
|
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
|
||||||
|
@ -173,6 +174,11 @@ again:
|
||||||
device->fd = -1;
|
device->fd = -1;
|
||||||
}
|
}
|
||||||
device->writeable = 0;
|
device->writeable = 0;
|
||||||
|
list_del(&device->dev_list);
|
||||||
|
/* free the memory */
|
||||||
|
free(device->name);
|
||||||
|
free(device->label);
|
||||||
|
free(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
seed_devices = fs_devices->seed;
|
seed_devices = fs_devices->seed;
|
||||||
|
@ -182,6 +188,7 @@ again:
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(fs_devices);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue