[PATCH 09/17] btrfs-progs: free memory before error exit in read_whole_eb

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Free the memory allocated to "multi" before the error
exit in read_whole_eb().  Set it to NULL after we free
it in the loop to avoid any potential double-free.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---
 disk-io.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 5aa9aa3..897d0cf 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -198,17 +198,21 @@ static int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, i
 				      mirror, NULL);
 		if (ret) {
 			printk("Couldn't map the block %Lu\n", eb->start + offset);
+			kfree(multi);
 			return -EIO;
 		}
 		device = multi->stripes[0].dev;
 
-		if (device->fd == 0)
+		if (device->fd == 0) {
+			kfree(multi);
 			return -EIO;
+		}
 
 		eb->fd = device->fd;
 		device->total_ios++;
 		eb->dev_bytenr = multi->stripes[0].physical;
 		kfree(multi);
+		multi = NULL;
 
 		if (read_len > bytes_left)
 			read_len = bytes_left;
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux