From: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>
To: Gaurav Singh <gaurav1086@gmail.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: nd <nd@arm.com>,
Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>,
nd <nd@arm.com>
Subject: Re: [dpdk-dev] [PATCH] lib/metrics: fix memory leak
Date: Tue, 11 Aug 2020 21:01:28 +0000 [thread overview]
Message-ID: <VI1PR0802MB24479D2E9380DA1DA2559AEB98450@VI1PR0802MB2447.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <20200808163906.8021-1-gaurav1086@gmail.com>
<snip>
>
> fix memory leak
>
> Fixes: c5b7197f66 ("telemetry: move some functions to metrics library")
>
> Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
> ---
> lib/librte_metrics/rte_metrics_telemetry.c | 21 ++++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/lib/librte_metrics/rte_metrics_telemetry.c
> b/lib/librte_metrics/rte_metrics_telemetry.c
> index 289ebae0b..7b6d1063c 100644
> --- a/lib/librte_metrics/rte_metrics_telemetry.c
> +++ b/lib/librte_metrics/rte_metrics_telemetry.c
> @@ -41,12 +41,17 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t
> port_id)
> }
>
> xstats_names = malloc(sizeof(*xstats_names) * num_xstats);
> + if (xstats_names == NULL) {
> + METRICS_LOG_ERR("Failed to malloc memory for
> xstats_names");
> + return -ENOMEM;
> + }
> +
> eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name)
> * num_xstats);
> - if (eth_xstats_names == NULL || xstats_names == NULL) {
> - METRICS_LOG_ERR("Failed to malloc memory for
> xstats_names");
> - ret = -ENOMEM;
> - goto free_xstats;
> + if (eth_xstats_names == NULL) {
> + METRICS_LOG_ERR("Failed to malloc memory for
> eth_xstats_names");
> + free(xstats_names);
> + return -ENOMEM;
> }
>
> if (rte_eth_xstats_get_names(port_id,
> @@ -167,9 +172,15 @@ rte_metrics_tel_format_port(uint32_t pid, json_t
> *ports,
> }
>
> metrics = malloc(sizeof(struct rte_metric_value) * num_metrics);
> + if (metrics == NULL) {
> + METRICS_LOG_ERR("Cannot allocate memory");
> + return -ENOMEM;
> + }
> +
> names = malloc(sizeof(struct rte_metric_name) * num_metrics);
> - if (metrics == NULL || names == NULL) {
> + if (names == NULL) {
> METRICS_LOG_ERR("Cannot allocate memory");
> + free(metrics);
> return -ENOMEM;
> }
>
> --
> 2.17.1
Looks good.
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
next prev parent reply other threads:[~2020-08-11 21:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-31 3:45 [dpdk-dev] [PATCH] librte_metrics: " Gaurav Singh
2020-07-31 4:54 ` Honnappa Nagarahalli
2020-08-01 1:46 ` Gaurav Singh
2020-08-01 6:08 ` Gaurav Singh
2020-08-01 23:34 ` Honnappa Nagarahalli
2020-08-08 16:39 ` [dpdk-dev] [PATCH] lib/metrics: " Gaurav Singh
2020-08-11 21:01 ` Honnappa Nagarahalli [this message]
2020-09-22 10:26 ` Power, Ciara
2020-10-30 14:59 ` David Marchand
2020-11-03 21:36 ` David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=VI1PR0802MB24479D2E9380DA1DA2559AEB98450@VI1PR0802MB2447.eurprd08.prod.outlook.com \
--to=honnappa.nagarahalli@arm.com \
--cc=dev@dpdk.org \
--cc=gaurav1086@gmail.com \
--cc=nd@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).