[PATCH v2] eventdev/eth_rx: fix memory leak when token parsing finished
Kundapura, Ganapati
ganapati.kundapura at intel.com
Wed Feb 2 17:47:27 CET 2022
Hi Weiguo,
Also noticed that usage of macros like RTE_EVENT_ETH_RX_ADAPTER_ID_VALID_OR_ERR_RET and
RTE_ETH_VALID_PORTID_OR_ERR_RET to validate rx_adapter_id and eth_dev_id returns error
bypassing the freeing of memory get from strdup() in error case.
Thanks,
Ganapati
> -----Original Message-----
> From: Kundapura, Ganapati <ganapati.kundapura at intel.com>
> Sent: 02 February 2022 20:24
> To: Kundapura, Ganapati <ganapati.kundapura at intel.com>; Weiguo Li
> <liwg06 at foxmail.com>; Jayatheerthan, Jay <jay.jayatheerthan at intel.com>
> Cc: Naga Harish K, S V <s.v.naga.harish.k at intel.com>; dev at dpdk.org
> Subject: RE: [PATCH v2] eventdev/eth_rx: fix memory leak when token
> parsing finished
>
> Hi Weigo,
> Could you please address the below issues also?
>
> Thanks,
> Ganapati
> > -----Original Message-----
> > From: Kundapura, Ganapati <ganapati.kundapura at intel.com>
> > Sent: 02 February 2022 13:18
> > To: Weiguo Li <liwg06 at foxmail.com>; Jayatheerthan, Jay
> > <jay.jayatheerthan at intel.com>
> > Cc: Naga Harish K, S V <s.v.naga.harish.k at intel.com>; dev at dpdk.org
> > Subject: RE: [PATCH v2] eventdev/eth_rx: fix memory leak when token
> > parsing finished
> >
> > Acked-by: Ganapati Kundapura<ganapati.kundapura at intel.com>
> >
> > > -----Original Message-----
> > > From: Weiguo Li <liwg06 at foxmail.com>
> > > Sent: 02 February 2022 13:11
> > > To: Jayatheerthan, Jay <jay.jayatheerthan at intel.com>
> > > Cc: Kundapura, Ganapati <ganapati.kundapura at intel.com>; Naga Harish
> > > K, S V <s.v.naga.harish.k at intel.com>; dev at dpdk.org
> > > Subject: [PATCH v2] eventdev/eth_rx: fix memory leak when token
> > > parsing finished
> > >
> > > 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 at foxmail.com>
> > > ---
> > > 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, ",");
> Validate token here
> > > 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);
> Use RTE_ETH_VALID_PORTID_OR_ERR_RET to validate eth_dev_id
> > >
> > > 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, ",");
> Validate token here
> > > 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);
> Use RTE_ETH_VALID_PORTID_OR_ERR_RET to validate eth_dev_id
> > >
> > > 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, ",");
> Validate token
> > > 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);
> Use RTE_ETH_VALID_PORTID_OR_ERR_RET to validate eth_dev_id
> > >
> > > 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
More information about the dev
mailing list