public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: robbieko <robbieko@synology.com>
To: linux-btrfs@vger.kernel.org
Cc: Robbie Ko <robbieko@synology.com>
Subject: [PATCH] btrfs: fix memory leak for page count
Date: Fri, 17 Jul 2020 18:22:40 +0800	[thread overview]
Message-ID: <20200717102240.21742-1-robbieko@synology.com> (raw)

From: Robbie Ko <robbieko@synology.com>

When lock_delalloc_page, we first lock the page and then
check that the page dirty, if the page is not dirty, we
will return -EAGAIN but all pages must be freed, otherwise
page leak.

Signed-off-by: Robbie Ko <robbieko@synology.com>
---
 fs/btrfs/extent_io.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 68c96057ad2d..34d55b1e2a88 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1951,7 +1951,7 @@ static int __process_pages_contig(struct address_space *mapping,
 	struct page *pages[16];
 	unsigned ret;
 	int err = 0;
-	int i;
+	int i, j;
 
 	if (page_ops & PAGE_LOCK) {
 		ASSERT(page_ops == PAGE_LOCK);
@@ -1999,7 +1999,8 @@ static int __process_pages_contig(struct address_space *mapping,
 				if (!PageDirty(pages[i]) ||
 				    pages[i]->mapping != mapping) {
 					unlock_page(pages[i]);
-					put_page(pages[i]);
+					for (j = i; j < ret; j++)
+						put_page(pages[j]);
 					err = -EAGAIN;
 					goto out;
 				}
-- 
2.17.1


             reply	other threads:[~2020-07-17 10:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17 10:22 robbieko [this message]
2020-07-17 12:00 ` [PATCH] btrfs: fix memory leak for page count Filipe Manana
2020-07-17 12:27   ` Nikolay Borisov
2020-07-20  1:27   ` Robbie Ko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200717102240.21742-1-robbieko@synology.com \
    --to=robbieko@synology.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox