From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 24030A00C5; Wed, 2 Feb 2022 08:41:00 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC7F140E03; Wed, 2 Feb 2022 08:40:59 +0100 (CET) Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) by mails.dpdk.org (Postfix) with ESMTP id A317A40DF4 for ; Wed, 2 Feb 2022 08:40:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1643787653; bh=46wpYxtChnSKpzZlvqax2wZ/6laq0sOaDJKQNx09X0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=joECYV8/MtrXlhlce39v4airs9KzRsOdijPFmwatDjh/QME/5E+dT4w5E31l8+JTb v8nCAtyve9OSdbnmeh0ump8lrKXQR0gvdKUuJC0C0fyHLtTqZaHCt+Cr/TvxNonK1o sAZ5a57dstlswKl6i5BdpsnGwz7DTB87/cmY0XK0= Received: from liwg-ubuntu.lan ([111.193.130.237]) by newxmesmtplogicsvrszc7.qq.com (NewEsmtp) with SMTP id A2A26A6F; Wed, 02 Feb 2022 15:40:42 +0800 X-QQ-mid: xmsmtpt1643787642t0d84xfko Message-ID: X-QQ-XMAILINFO: N7uwkaxM/iW8Y5/9GRYkOtZAkCstYFlXtH7AiQHTMO6ZHDlHCARnWXPoyhU8R6 CtDcDNVZ/n6BqcHsi4l69AtQjfGMaBDZyPCSYbQwLtpJZ0rPyK2N5UsoKR4dEk6mQeotbT9iztJ+ IKyjER47bXGhUR0Qv4oyluzYZ4teBoelqCEW8Sx3aO/FJeipJEHAXmRvEzjX7zlQhwSuJdrDFRLV v+FBsPqFSdoo2iId/UptYEFgSRL+FTz5nSKjyCmpYleliEr8SMpLWbhRxFzJkncNf9ignrBKrNVj DwKWEGgP8Sa3tw/Dxm+iWR+P+Imus4XJ5dzvkSby57ppmsuwUCHsaDICHeqWEQWqjCTF7u3+VVzT YqDRo/jLk0SghZ8J4Z8M1zORNQ3sXXa8aaNd5SjSXQwJR6mF5A+xfTtmb3r+kHerUcrwqYOWviGY WRjlqFcuM/njIx4tjoiarpOvCgSuqhnkc3vN5A24asDClDd/X8OZLcvPjnwGznE4DGwTek3og0aC 8H19EfdZazlI4e/So4U3tPEELHgS4g5PXY3VA1KmxXM1Ys49IqbzfoI3jJKnCxblPsbKhfA84KIk SvaPi1xVgDVMhXol81+HZysHIdJ2t2R0vY1LN/7SDScVIjn/4/mXnjtIwhjHdW5qG8R5q2bjGjYR cmQuPwK8QPxt29xyT+Z761NAk1AGD5aBgOy5sCwOBlLa+gCAb+YOpQMUo2TlWXOgW7P2w5m2utm0 6lkXwcPbfuS7743ecqhERxqB3gJrcmr+a3ywBfNZ7+/k930j4XN2EZ/7m+SqGnD2p0qLw4avgzeQ TSAO/h0G/eTJtpK8ZJM7FekZ9lzGltPYv9D1nAp9yrlf0/eM9fJah7HbhAsxyJ3+z8GoJ/KclOBw == From: Weiguo Li To: jay.jayatheerthan@intel.com Cc: ganapati.kundapura@intel.com, s.v.naga.harish.k@intel.com, dev@dpdk.org Subject: [PATCH v2] eventdev/eth_rx: fix memory leak when token parsing finished Date: Wed, 2 Feb 2022 15:40:41 +0800 X-OQ-MSGID: <20220202074041.1613498-1-liwg06@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The memory get from strdup should be freed when parameter parsing finished, and also should be freed when error occurs. Fixes: 814d01709328 ("eventdev/eth_rx: support telemetry") Fixes: 9e583185318f ("eventdev/eth_rx: support telemetry") Signed-off-by: Weiguo Li --- v2: * add memory check after strdup --- lib/eventdev/rte_event_eth_rx_adapter.c | 45 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c index ae1e260c08..8519c98b19 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -3332,26 +3332,31 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, /* Get Rx adapter ID from parameter string */ l_params = strdup(params); + if (l_params == NULL) + return -ENOMEM; token = strtok(l_params, ","); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(rx_adapter_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) + if (token == NULL || strlen(token) == 0 || !isdigit(*token)) { + free(l_params); return -1; - + } /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(eth_dev_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) + if (token == NULL || strlen(token) == 0 || !isdigit(*token)) { + free(l_params); return -1; - + } /* Get Rx queue ID from parameter string */ rx_queue_id = strtoul(token, NULL, 10); if (rx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_rx_queues) { RTE_EDEV_LOG_ERR("Invalid rx queue_id %u", rx_queue_id); + free(l_params); return -EINVAL; } @@ -3359,6 +3364,8 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); + /* Parsing parameter finished */ + free(l_params); if (rte_event_eth_rx_adapter_queue_conf_get(rx_adapter_id, eth_dev_id, rx_queue_id, &queue_conf)) { @@ -3396,26 +3403,31 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, /* Get Rx adapter ID from parameter string */ l_params = strdup(params); + if (l_params == NULL) + return -ENOMEM; token = strtok(l_params, ","); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(rx_adapter_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) + if (token == NULL || strlen(token) == 0 || !isdigit(*token)) { + free(l_params); return -1; - + } /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(eth_dev_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) + if (token == NULL || strlen(token) == 0 || !isdigit(*token)) { + free(l_params); return -1; - + } /* Get Rx queue ID from parameter string */ rx_queue_id = strtoul(token, NULL, 10); if (rx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_rx_queues) { RTE_EDEV_LOG_ERR("Invalid rx queue_id %u", rx_queue_id); + free(l_params); return -EINVAL; } @@ -3423,6 +3435,8 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); + /* Parsing parameter finished */ + free(l_params); if (rte_event_eth_rx_adapter_queue_stats_get(rx_adapter_id, eth_dev_id, rx_queue_id, &q_stats)) { @@ -3458,26 +3472,31 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, /* Get Rx adapter ID from parameter string */ l_params = strdup(params); + if (l_params == NULL) + return -ENOMEM; token = strtok(l_params, ","); rx_adapter_id = strtoul(token, NULL, 10); RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET(rx_adapter_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) + if (token == NULL || strlen(token) == 0 || !isdigit(*token)) { + free(l_params); return -1; - + } /* Get device ID from parameter string */ eth_dev_id = strtoul(token, NULL, 10); RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(eth_dev_id, -EINVAL); token = strtok(NULL, ","); - if (token == NULL || strlen(token) == 0 || !isdigit(*token)) + if (token == NULL || strlen(token) == 0 || !isdigit(*token)) { + free(l_params); return -1; - + } /* Get Rx queue ID from parameter string */ rx_queue_id = strtoul(token, NULL, 10); if (rx_queue_id >= rte_eth_devices[eth_dev_id].data->nb_rx_queues) { RTE_EDEV_LOG_ERR("Invalid rx queue_id %u", rx_queue_id); + free(l_params); return -EINVAL; } @@ -3485,6 +3504,8 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, if (token != NULL) RTE_EDEV_LOG_ERR("Extra parameters passed to eventdev" " telemetry command, ignoring"); + /* Parsing parameter finished */ + free(l_params); if (rte_event_eth_rx_adapter_queue_stats_reset(rx_adapter_id, eth_dev_id, -- 2.25.1