diff mbox

NFC: nci: fix memory leak

Message ID 1447678635-11146-1-git-send-email-sudipm.mukherjee@gmail.com
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Sudip Mukherjee Nov. 16, 2015, 12:57 p.m. UTC
In case of invalid number_destination_params we were returning error but
we missed releasing cmd. Lets check for the number of parameter before
allocating memory so that we don't have a memory leak.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
 net/nfc/nci/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Sudip Mukherjee Dec. 9, 2015, 11:59 a.m. UTC | #1
On Mon, Nov 16, 2015 at 06:27:15PM +0530, Sudip Mukherjee wrote:
> In case of invalid number_destination_params we were returning error but
> we missed releasing cmd. Lets check for the number of parameter before
> allocating memory so that we don't have a memory leak.
> 
> Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
> ---

A gentle ping.

regards
sudip


>  net/nfc/nci/core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
> index 10c99a5..fbb7a2b 100644
> --- a/net/nfc/nci/core.c
> +++ b/net/nfc/nci/core.c
> @@ -610,14 +610,14 @@ int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type,
>  	struct nci_core_conn_create_cmd *cmd;
>  	struct core_conn_create_data data;
>  
> +	if (!number_destination_params)
> +		return -EINVAL;
> +
>  	data.length = params_len + sizeof(struct nci_core_conn_create_cmd);
>  	cmd = kzalloc(data.length, GFP_KERNEL);
>  	if (!cmd)
>  		return -ENOMEM;
>  
> -	if (!number_destination_params)
> -		return -EINVAL;
> -
>  	cmd->destination_type = destination_type;
>  	cmd->number_destination_params = number_destination_params;
>  	memcpy(cmd->params, params, params_len);
> -- 
> 1.9.1
> 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 10c99a5..fbb7a2b 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -610,14 +610,14 @@  int nci_core_conn_create(struct nci_dev *ndev, u8 destination_type,
 	struct nci_core_conn_create_cmd *cmd;
 	struct core_conn_create_data data;
 
+	if (!number_destination_params)
+		return -EINVAL;
+
 	data.length = params_len + sizeof(struct nci_core_conn_create_cmd);
 	cmd = kzalloc(data.length, GFP_KERNEL);
 	if (!cmd)
 		return -ENOMEM;
 
-	if (!number_destination_params)
-		return -EINVAL;
-
 	cmd->destination_type = destination_type;
 	cmd->number_destination_params = number_destination_params;
 	memcpy(cmd->params, params, params_len);