Skip to content

Commit 22e7987

Browse files
ying-xuedavem330
authored andcommitted
tipc: fix a possible memory leak
The commit a8b9b96 ("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: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a42c3a2 commit 22e7987

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎net/tipc/discover.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,10 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest)
348348
return -ENOMEM;
349349

350350
req->buf = tipc_buf_acquire(INT_H_SIZE);
351-
if (!req->buf)
351+
if (!req->buf) {
352+
kfree(req);
352353
return -ENOMEM;
354+
}
353355

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

0 commit comments

Comments
 (0)