tipc: fix a possible memory leak
authorYing Xue <ying.xue@windriver.com>
Fri, 25 Apr 2014 02:44:15 +0000 (10:44 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 27 Apr 2014 23:08:06 +0000 (19:08 -0400)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tipc/discover.c

index ada42e436f5e78ee29b506639d77cc4116e61cbb..bd35c4a0746f3aba884ad71b3f6a17e0f4e25155 100644 (file)
@@ -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));