Skip to contentSkip to conversation

NFC: nci: memory leak in nci_core_conn_create()

PATCH New Dan Carpenter 1 participant 1 message Nov 4, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFC: nci: memory leak in nci_core_conn_create()

I've moved the check for "number_destination_params" forward a few lines to avoid leaking "cmd".

Fixes caa575a86ec1 ('NFC: nci: fix possible crash in nci_core_conn_create')
net/nfc/nci/core.c +3 -3
index 10c99a5..fbb7a2b 100644
@@ -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);