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

Commit 22e7987a authored by Ying Xue's avatar Ying Xue Committed by David S. Miller
Browse files

tipc: fix a possible memory leak



The commit a8b9b96e ("tipc: fix race
in disc create/delete") leads to the following static checker warning:

	net/tipc/discover.c:352 tipc_disc_create()
		warn: possible memory leak of 'req'

The risk of memory leak really exists in practice. Especially when
it's failed to allocate memory for "req->buf", tipc_disc_create()
doesn't free its allocated memory, instead just directly returns
with ENOMEM error code. In this situation, memory leak, of course,
happens.

Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarYing Xue <ying.xue@windriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a42c3a28
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -348,8 +348,10 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest)
		return -ENOMEM;
		return -ENOMEM;


	req->buf = tipc_buf_acquire(INT_H_SIZE);
	req->buf = tipc_buf_acquire(INT_H_SIZE);
	if (!req->buf)
	if (!req->buf) {
		kfree(req);
		return -ENOMEM;
		return -ENOMEM;
	}


	tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr);
	tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr);
	memcpy(&req->dest, dest, sizeof(*dest));
	memcpy(&req->dest, dest, sizeof(*dest));