* [PATCH] eventdev/eth_rx: fix memory leak when token parsing finished
@ 2022-02-02 6:15 Weiguo Li
0 siblings, 0 replies; 3+ messages in thread
From: Weiguo Li @ 2022-02-02 6:15 UTC (permalink / raw)
To: jay.jayatheerthan; +Cc: ganapati.kundapura, s.v.naga.harish.k, dev
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 <liwg06@foxmail.com>
---
lib/eventdev/rte_event_eth_rx_adapter.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/lib/eventdev/rte_event_eth_rx_adapter.c b/lib/eventdev/rte_event_eth_rx_adapter.c
index ae1e260c08..4173a52981 100644
--- a/lib/eventdev/rte_event_eth_rx_adapter.c
+++ b/lib/eventdev/rte_event_eth_rx_adapter.c
@@ -3338,6 +3338,7 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
token = strtok(NULL, ",");
if (token == NULL || strlen(token) == 0 || !isdigit(*token))
+ free(l_params);
return -1;
/* Get device ID from parameter string */
@@ -3346,12 +3347,14 @@ handle_rxa_get_queue_conf(const char *cmd __rte_unused,
token = strtok(NULL, ",");
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)) {
@@ -3402,6 +3407,7 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
token = strtok(NULL, ",");
if (token == NULL || strlen(token) == 0 || !isdigit(*token))
+ free(l_params);
return -1;
/* Get device ID from parameter string */
@@ -3410,12 +3416,14 @@ handle_rxa_get_queue_stats(const char *cmd __rte_unused,
token = strtok(NULL, ",");
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)) {
@@ -3464,6 +3474,7 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
token = strtok(NULL, ",");
if (token == NULL || strlen(token) == 0 || !isdigit(*token))
+ free(l_params);
return -1;
/* Get device ID from parameter string */
@@ -3472,12 +3483,14 @@ handle_rxa_queue_stats_reset(const char *cmd __rte_unused,
token = strtok(NULL, ",");
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] eventdev/eth_rx: fix memory leak when token parsing finished
@ 2022-02-02 7:13 Weiguo Li
2022-02-03 6:02 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Weiguo Li @ 2022-02-02 7:13 UTC (permalink / raw)
To: jay.jayatheerthan; +Cc: ganapati.kundapura, s.v.naga.harish.k, dev
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 <liwg06@foxmail.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] eventdev/eth_rx: fix memory leak when token parsing finished
2022-02-02 7:13 Weiguo Li
@ 2022-02-03 6:02 ` Stephen Hemminger
0 siblings, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2022-02-03 6:02 UTC (permalink / raw)
To: Weiguo Li; +Cc: jay.jayatheerthan, ganapati.kundapura, s.v.naga.harish.k, dev
On Wed, 2 Feb 2022 15:13:22 +0800
Weiguo Li <liwg06@foxmail.com> wrote:
> 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 <liwg06@foxmail.com>
strdupa() is easier to use here instead of strdup().
Also, the code is not checking for strdup failing...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-03 6:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 6:15 [PATCH] eventdev/eth_rx: fix memory leak when token parsing finished Weiguo Li
2022-02-02 7:13 Weiguo Li
2022-02-03 6:02 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).