Skip to content

Commit

Permalink
ksmbd: prevent memory leak on error return
Browse files Browse the repository at this point in the history
When allocated memory for 'new' failed,just return
will cause memory leak of 'ar'.

Fixes: 1819a90 ("ksmbd: reorganize ksmbd_iov_pin_rsp()")
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Closes: https://lore.kernel.org/r/[email protected]/
Signed-off-by: Zongmin Zhou<[email protected]>
Acked-by: Namjae Jeon <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
Zongmin Zhou authored and Steve French committed Nov 24, 2023
1 parent 98b1cc8 commit 9004448
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fs/smb/server/ksmbd_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static inline void __ksmbd_iov_pin(struct ksmbd_work *work, void *ib,
static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
void *aux_buf, unsigned int aux_size)
{
struct aux_read *ar;
struct aux_read *ar = NULL;
int need_iov_cnt = 1;

if (aux_size) {
Expand All @@ -123,8 +123,11 @@ static int __ksmbd_iov_pin_rsp(struct ksmbd_work *work, void *ib, int len,
new = krealloc(work->iov,
sizeof(struct kvec) * work->iov_alloc_cnt,
GFP_KERNEL | __GFP_ZERO);
if (!new)
if (!new) {
kfree(ar);
work->iov_alloc_cnt -= 4;
return -ENOMEM;
}
work->iov = new;
}

Expand Down

0 comments on commit 9004448

Please sign in to comment.