aboutsummaryrefslogtreecommitdiffstats
path: root/volumes.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2014-03-14 03:28:11 +0000
committerChris Mason <clm@fb.com>2014-03-21 09:51:31 -0700
commit9d57509e99a65732e9905402b36ea8b8d591e541 (patch)
tree35e9b88051f6ab3df978ef21aea9244881bde078 /volumes.c
parent64200e4453f0f23bef42919db7854b6e8ed2ceda (diff)
downloadbtrfs-progs-9d57509e99a65732e9905402b36ea8b8d591e541.tar.gz
btrfs-progs-9d57509e99a65732e9905402b36ea8b8d591e541.tar.xz
btrfs-progs-9d57509e99a65732e9905402b36ea8b8d591e541.zip
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>
Diffstat (limited to 'volumes.c')
-rw-r--r--volumes.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/volumes.c b/volumes.c
index 8c45851..77ffd32 100644
--- a/volumes.c
+++ b/volumes.c
@@ -160,11 +160,12 @@ static int device_list_add(const char *path,
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))
@@ -173,6 +174,11 @@ again:
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;
@@ -182,6 +188,7 @@ again:
goto again;
}
+ free(fs_devices);
return 0;
}