Message ID | d012eb57320bc93ec45583a7ff86575060bcf51c.1676031742.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: send: fix cache entry leak after failure to add it to the name cache | expand |
On Fri, Feb 10, 2023 at 12:27:35PM +0000, fdmanana@kernel.org wrote: > From: Filipe Manana <fdmanana@suse.com> > > At __get_cur_name_and_parent(), if we fail to insert a name cache entry to > the name cache, we end up returning without freeing the entry, resulting > in a memory leak. Fix this by freeing the entry if the insertion fails. > > The issue was introduced by the following patch: > > "btrfs: send: use the lru cache to implement the name cache" Folded to the patch, thanks.
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index f936c203f386..e5c963bb873d 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -2385,8 +2385,10 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx, nce->need_later_update = 1; nce_ret = btrfs_lru_cache_store(&sctx->name_cache, &nce->entry, GFP_KERNEL); - if (nce_ret < 0) + if (nce_ret < 0) { + kfree(nce); ret = nce_ret; + } out: return ret;