From 7bf4aa61a77b9ff6d0c066d370b03e67a2eaade4 Mon Sep 17 00:00:00 2001 From: Justin Husted Date: Sat, 9 Nov 2019 18:53:20 -0800 Subject: [PATCH] Fix memory leak in fuse write. The write buffer was being leaked in bcachefs_fuse_write(). Signed-off-by: Justin Husted --- cmd_fusemount.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd_fusemount.c b/cmd_fusemount.c index c770bdfc..de03ca18 100644 --- a/cmd_fusemount.c +++ b/cmd_fusemount.c @@ -609,6 +609,8 @@ static void bcachefs_fuse_write(fuse_req_t req, fuse_ino_t inum, inum, size, offset); struct fuse_align_io align = align_io(c, size, offset); + void *aligned_buf = aligned_alloc(PAGE_SIZE, align.size); + BUG_ON(!aligned_buf); if (get_inode_io_opts(c, inum, &io_opts)) { ret = -ENOENT; @@ -616,7 +618,6 @@ static void bcachefs_fuse_write(fuse_req_t req, fuse_ino_t inum, } /* Realign the data and read in start and end, if needed */ - void *aligned_buf = aligned_alloc(PAGE_SIZE, align.size); /* Read partial start data. */ if (align.pad_start) { @@ -673,11 +674,13 @@ static void bcachefs_fuse_write(fuse_req_t req, fuse_ino_t inum, if (!ret) { BUG_ON(written == 0); fuse_reply_write(req, written); + free(aligned_buf); return; } err: fuse_reply_err(req, -ret); + free(aligned_buf); } static void bcachefs_fuse_symlink(fuse_req_t req, const char *link, @@ -705,6 +708,8 @@ static void bcachefs_fuse_symlink(fuse_req_t req, const char *link, struct fuse_align_io align = align_io(c, link_len + 1, 0); void *aligned_buf = aligned_alloc(PAGE_SIZE, align.size); + BUG_ON(!aligned_buf); + memset(aligned_buf, 0, align.size); memcpy(aligned_buf, link, link_len); /* already terminated */