From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0A73C433F5 for ; Wed, 2 Feb 2022 07:13:49 +0000 (UTC) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3BFE240E03; Wed, 2 Feb 2022 08:13:49 +0100 (CET) Received: from out203-205-221-191.mail.qq.com (out203-205-221-191.mail.qq.com [203.205.221.191]) by mails.dpdk.org (Postfix) with ESMTP id 5624E40DF4 for ; Wed, 2 Feb 2022 08:13:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1643786023; bh=BUGC/nm7PEAFHpMOH6yve2z/w9dL4v58UmzpzfIaJcg=; h=From:To:Cc:Subject:Date; b=JqMPGB/BKmVClfUKn/infHR0zZ9LaCaRpxFpkYeeeYn7qwChRF2+fmkhquz3uNG/X PrPL8UFP3r12jRaCNM0BYBmpl4oFjVXoEZ5xu0wguxyzVygukVPr1pwd/no/bgJnsZ FoE7yKiGB7ty6PJZSF3lLtVv9R/mGPppEVCgcfBk= Received: from liwg-ubuntu.lan ([111.193.130.237]) by newxmesmtplogicsvrsza9.qq.com (NewEsmtp) with SMTP id 356938A3; Wed, 02 Feb 2022 15:13:22 +0800 X-QQ-mid: xmsmtpt1643786002tabr0w7ar Message-ID: X-QQ-XMAILINFO: MgFdfbcSIv5JCPU+QXgj61qLQrxkkbSANPylA0K+fMh0LtHiy0gHoF050dWIY9 YStgBkBb7uubG9Ut/n6lm4EBaBaW0ge3fPWHO1rAdxw+NgDL337hHjTtKMLXVWz3S2SglToeedDa /0GvKUHYv1AFWtc3wlSI4y9Dktvtvd/GV2qxgq4xOUkuzrsFn/OZCfG/UgDyVAs2tQychv1GSoVX cPouw6d2CcY+/MkdwEevMC+api7yegCu3tUWOw7M2ulThkGImAHzlLmrlBC4mZ1QJepbmAep4jSm mCZxbf1dYigNbda9ch/cXEk0eOsSBuQLYkpgIInle09toIL7kUqKzOsN/kYIMujRVwzH7KNSb4Rv 57lZy4ixAN4WzQqLGV4S6Fr3HsoBueM0njs1P6CHgeAv4o+TTFHaKhYltIzoNC6C72gfwuVXMCdi utymNM2ItnT2cMYrv0AbEZ0vKU41nFNpAip5pdbm/+AW/9IBEb63urM31cVfILyjeXQp/u6Ep0Pz 7HXYg8KSZgn911gbmnqPBUYk+/F6UiTSo2NTX4yD/uIAJDilHOpEn88ouAKuIYXIC45PytWi2qCf 5vnmI/dNsCSA0bZsT8m6ewe83vjzje13I2w1bRnggLul4Y4s+4UWHQBl2GBHJGKwtFqHG9nBHJt+ 77yz8YBwPD/KRBYn8XzRM/tFkRW9pLUO5fN2qgKpO8/kEHqWrGMf/UiRBsweZyic+Z2VyV/KOkBt 7arHPYiJTlDytmOtRUsz7uRo/8chrkIiLhg6saYqXOcD/1rRh5xNEKmgz8oyC72cO0AnjGDhKI5z /aAMAXIf897KLQyE/A7l4bcK5guA9i+9n9/SirCLgEgkFh0nPfVEG8mIGWDIHWyw8= 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] eventdev/eth_rx: fix memory leak when token parsing finished Date: Wed, 2 Feb 2022 15:13:22 +0800 X-OQ-MSGID: <20220202071322.1608192-1-liwg06@foxmail.com> X-Mailer: git-send-email 2.25.1 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 --- lib/eventdev/rte_event_eth_rx_adapter.c | 39 +++++++++++++++++-------- 1 file changed, 27 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..44775575a2 100644 --- a/lib/eventdev/rte_event_eth_rx_adapter.c +++ b/lib/eventdev/rte_event_eth_rx_adapter.c @@ -3337,21 +3337,24 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused, 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 +3362,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)) { @@ -3401,21 +3406,24 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused, 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 +3431,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)) { @@ -3463,21 +3473,24 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused, 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 +3498,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