Skip to content

Commit

Permalink
locks: fix a memory leak bug in __break_lease()
Browse files Browse the repository at this point in the history
In __break_lease(), the file lock 'new_fl' is allocated in lease_alloc().
However, it is not deallocated in the following execution if
smp_load_acquire() fails, leading to a memory leak bug. To fix this issue,
free 'new_fl' before returning the error.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
  • Loading branch information
Wenwen Wang authored and Jeff Layton committed Aug 20, 2019
1 parent df2474a commit cfddf9f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
ctx = smp_load_acquire(&inode->i_flctx);
if (!ctx) {
WARN_ON_ONCE(1);
return error;
goto free_lock;
}

percpu_down_read(&file_rwsem);
Expand Down Expand Up @@ -1672,6 +1672,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
spin_unlock(&ctx->flc_lock);
percpu_up_read(&file_rwsem);
locks_dispose_list(&dispose);
free_lock:
locks_free_lock(new_fl);
return error;
}
Expand Down

0 comments on commit cfddf9f

Please sign in to comment.