Netdev Archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] tipc: fix a possible memory leak
@ 2014-04-25  2:44 Ying Xue
  2014-04-27 23:08 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Ying Xue @ 2014-04-25  2:44 UTC (permalink / raw
  To: dan.carpenter
  Cc: davem, jon.maloy, Paul.Gortmaker, erik.hugne, netdev,
	tipc-discussion

The commit a8b9b96e959f3c035af20b1bd2ba67b0b7269b19 ("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>
---
 net/tipc/discover.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/tipc/discover.c b/net/tipc/discover.c
index ada42e4..bd35c4a 100644
--- a/net/tipc/discover.c
+++ b/net/tipc/discover.c
@@ -348,8 +348,10 @@ int tipc_disc_create(struct tipc_bearer *b_ptr, struct tipc_media_addr *dest)
 		return -ENOMEM;
 
 	req->buf = tipc_buf_acquire(INT_H_SIZE);
-	if (!req->buf)
+	if (!req->buf) {
+		kfree(req);
 		return -ENOMEM;
+	}
 
 	tipc_disc_init_msg(req->buf, DSC_REQ_MSG, b_ptr);
 	memcpy(&req->dest, dest, sizeof(*dest));
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] tipc: fix a possible memory leak
  2014-04-25  2:44 [PATCH net-next] tipc: fix a possible memory leak Ying Xue
@ 2014-04-27 23:08 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-04-27 23:08 UTC (permalink / raw
  To: ying.xue
  Cc: jon.maloy, netdev, Paul.Gortmaker, tipc-discussion, dan.carpenter

From: Ying Xue <ying.xue@windriver.com>
Date: Fri, 25 Apr 2014 10:44:15 +0800

> The commit a8b9b96e959f3c035af20b1bd2ba67b0b7269b19 ("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>

Applied, thanks.

------------------------------------------------------------------------------
Start Your Social Network Today - Download eXo Platform
Build your Enterprise Intranet with eXo Platform Software
Java Based Open Source Intranet - Social, Extensible, Cloud Ready
Get Started Now And Turn Your Intranet Into A Collaboration Platform
http://p.sf.net/sfu/ExoPlatform

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-27 23:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-25  2:44 [PATCH net-next] tipc: fix a possible memory leak Ying Xue
2014-04-27 23:08 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).