btrfs: fix inode leak on failure to add link to inode
authorFilipe Manana <fdmanana@suse.com>
Fri, 25 Jul 2025 15:54:49 +0000 (16:54 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 21 Aug 2025 22:58:27 +0000 (00:58 +0200)
commite87e953bb20629ca1f008f8146c38e313e5ed319
treeb7587daa1d3df93797179f9ba03ff46e42b4ea84
parent2b3979624c3e34dcdd77d910c6490939727d91b2
btrfs: fix inode leak on failure to add link to inode

If we fail to update the inode or delete the orphan item we leak the inode
since we update its refcount with the ihold() call to account for the
d_instantiate() call which never happens in case we fail those steps. Fix
this by setting 'drop_inode' to true in case we fail those steps.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c