Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d06b0d2 authored by David Howells's avatar David Howells
Browse files

afs: Fix page leak in afs_write_begin()



afs_write_begin() leaks a ref and a lock on a page if afs_fill_page()
fails.  Fix the leak by unlocking and releasing the page in the error path.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 68ae849d
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -154,12 +154,12 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
		kfree(candidate);
		kfree(candidate);
		return -ENOMEM;
		return -ENOMEM;
	}
	}
	*pagep = page;
	/* page won't leak in error case: it eventually gets cleaned off LRU */


	if (!PageUptodate(page) && len != PAGE_SIZE) {
	if (!PageUptodate(page) && len != PAGE_SIZE) {
		ret = afs_fill_page(vnode, key, pos & PAGE_MASK, PAGE_SIZE, page);
		ret = afs_fill_page(vnode, key, pos & PAGE_MASK, PAGE_SIZE, page);
		if (ret < 0) {
		if (ret < 0) {
			unlock_page(page);
			put_page(page);
			kfree(candidate);
			kfree(candidate);
			_leave(" = %d [prep]", ret);
			_leave(" = %d [prep]", ret);
			return ret;
			return ret;
@@ -167,6 +167,9 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
		SetPageUptodate(page);
		SetPageUptodate(page);
	}
	}


	/* page won't leak in error case: it eventually gets cleaned off LRU */
	*pagep = page;

try_again:
try_again:
	spin_lock(&vnode->writeback_lock);
	spin_lock(&vnode->writeback_lock);