DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] librte_metrics: fix memory leak
@ 2020-07-31  3:45 Gaurav Singh
  2020-07-31  4:54 ` Honnappa Nagarahalli
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Gaurav Singh @ 2020-07-31  3:45 UTC (permalink / raw)
  To: dev; +Cc: Gaurav Singh

Fix memory leak for sequential allocations.

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 lib/librte_metrics/rte_metrics_telemetry.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c
index 289ebae0b..55c2b8478 100644
--- a/lib/librte_metrics/rte_metrics_telemetry.c
+++ b/lib/librte_metrics/rte_metrics_telemetry.c
@@ -167,9 +167,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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_metrics: fix memory leak
  2020-07-31  3:45 [dpdk-dev] [PATCH] librte_metrics: fix memory leak Gaurav Singh
@ 2020-07-31  4:54 ` Honnappa Nagarahalli
  2020-08-01  1:46 ` Gaurav Singh
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Honnappa Nagarahalli @ 2020-07-31  4:54 UTC (permalink / raw)
  To: Gaurav Singh, dev; +Cc: nd, Honnappa Nagarahalli, nd

<snip>

Hi Gaurav,
	One comment inline.

> 
> Fix memory leak for sequential allocations.
> 
> Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
> ---
>  lib/librte_metrics/rte_metrics_telemetry.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/librte_metrics/rte_metrics_telemetry.c
> b/lib/librte_metrics/rte_metrics_telemetry.c
> index 289ebae0b..55c2b8478 100644
> --- a/lib/librte_metrics/rte_metrics_telemetry.c
> +++ b/lib/librte_metrics/rte_metrics_telemetry.c
> @@ -167,9 +167,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;
>  	}
There is a similar error in function 'rte_metrics_tel_reg_port_ethdev_to_metrics', can you fix that as well?

> 
> --
> 2.17.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH] librte_metrics: fix memory leak
  2020-07-31  3:45 [dpdk-dev] [PATCH] librte_metrics: fix memory leak 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-08 16:39 ` [dpdk-dev] [PATCH] lib/metrics: " Gaurav Singh
  3 siblings, 0 replies; 10+ messages in thread
From: Gaurav Singh @ 2020-08-01  1:46 UTC (permalink / raw)
  To: dev; +Cc: Gaurav Singh

Fix memory leak for sequential allocations.

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 lib/librte_metrics/rte_metrics_telemetry.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c
index 289ebae0b..e12c69fe0 100644
--- a/lib/librte_metrics/rte_metrics_telemetry.c
+++ b/lib/librte_metrics/rte_metrics_telemetry.c
@@ -41,11 +41,18 @@ 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");
+		ret = -ENOMEM;
+		goto free_xstats;
+	}
+
 	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name)
 			* num_xstats);
-	if (eth_xstats_names == NULL || xstats_names == NULL) {
+	if (eth_xstats_names == NULL) {
 		METRICS_LOG_ERR("Failed to malloc memory for xstats_names");
 		ret = -ENOMEM;
+		free(xstats_names);
 		goto free_xstats;
 	}
 
@@ -167,9 +174,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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH] librte_metrics: fix memory leak
  2020-07-31  3:45 [dpdk-dev] [PATCH] librte_metrics: fix memory leak 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
  3 siblings, 1 reply; 10+ messages in thread
From: Gaurav Singh @ 2020-08-01  6:08 UTC (permalink / raw)
  To: dev; +Cc: Gaurav Singh

Fix memory leak issue

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 lib/librte_metrics/rte_metrics_telemetry.c | 24 +++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/lib/librte_metrics/rte_metrics_telemetry.c b/lib/librte_metrics/rte_metrics_telemetry.c
index 289ebae0b..9fbe59c62 100644
--- a/lib/librte_metrics/rte_metrics_telemetry.c
+++ b/lib/librte_metrics/rte_metrics_telemetry.c
@@ -41,12 +41,19 @@ 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");
+		ret = -ENOMEM;
+		return ret;
+	}
+
 	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name)
 			* num_xstats);
-	if (eth_xstats_names == NULL || xstats_names == NULL) {
+	if (eth_xstats_names == NULL) {
 		METRICS_LOG_ERR("Failed to malloc memory for xstats_names");
 		ret = -ENOMEM;
-		goto free_xstats;
+		free(xstats_names);
+		return ret;
 	}
 
 	if (rte_eth_xstats_get_names(port_id,
@@ -54,7 +61,7 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t port_id)
 		METRICS_LOG_ERR("rte_eth_xstats_get_names(%u) len %d failed",
 				port_id, num_xstats);
 		ret = -EPERM;
-		goto free_xstats;
+		return ret;
 	}
 
 	for (i = 0; i < num_xstats; i++)
@@ -63,9 +70,6 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t port_id)
 	if (ret < 0)
 		METRICS_LOG_ERR("rte_metrics_reg_names failed - metrics may already be registered");
 
-free_xstats:
-	free(eth_xstats_names);
-	free(xstats_names);
 	return ret;
 }
 
@@ -167,9 +171,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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] librte_metrics: fix memory leak
  2020-08-01  6:08 ` Gaurav Singh
@ 2020-08-01 23:34   ` Honnappa Nagarahalli
  0 siblings, 0 replies; 10+ messages in thread
From: Honnappa Nagarahalli @ 2020-08-01 23:34 UTC (permalink / raw)
  To: Gaurav Singh, dev; +Cc: nd, Honnappa Nagarahalli, nd

Hi Gaurav,
	Thanks for the fix. Few comments inline. Also, please follow contributing guidelines [1].  There is a cheat sheet [2] which is very helpful.

[1] https://doc.dpdk.org/guides/contributing/index.html
[2] https://doc.dpdk.org/guides/contributing/cheatsheet.html

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Gaurav Singh
> Sent: Saturday, August 1, 2020 1:09 AM
> To: dev@dpdk.org
> Cc: Gaurav Singh <gaurav1086@gmail.com>
> Subject: [dpdk-dev] [PATCH] librte_metrics: fix memory leak
                                                       ^^^^^^^^^^^^ should be 'lib/metrics'
> 
> 
> Fix memory leak issue
> 
Needs "Fixes" tag and Cc to stable@dpdk.org (check the contribution guidelines)

> Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
> ---
>  lib/librte_metrics/rte_metrics_telemetry.c | 24 +++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/librte_metrics/rte_metrics_telemetry.c
> b/lib/librte_metrics/rte_metrics_telemetry.c
> index 289ebae0b..9fbe59c62 100644
> --- a/lib/librte_metrics/rte_metrics_telemetry.c
> +++ b/lib/librte_metrics/rte_metrics_telemetry.c
> @@ -41,12 +41,19 @@ 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");
> +		ret = -ENOMEM;
> +		return ret;
You can return -ENOMEM directly without assigning it to 'ret'

> +	}
> +
>  	eth_xstats_names = malloc(sizeof(struct rte_eth_xstat_name)
>  			* num_xstats);
> -	if (eth_xstats_names == NULL || xstats_names == NULL) {
> +	if (eth_xstats_names == NULL) {
>  		METRICS_LOG_ERR("Failed to malloc memory for
> xstats_names");
   ^^^^^^^^^^^^ I think it is worth changing to eth_xstats_names

>  		ret = -ENOMEM;
> -		goto free_xstats;
> +		free(xstats_names);
> +		return ret;
Same here, return -ENOMEM directly

>  	}
> 
>  	if (rte_eth_xstats_get_names(port_id,
> @@ -54,7 +61,7 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t
> port_id)
>  		METRICS_LOG_ERR("rte_eth_xstats_get_names(%u) len %d
> failed",
>  				port_id, num_xstats);
>  		ret = -EPERM;
> -		goto free_xstats;
> +		return ret;
Any reason for this change? This change leaks memory.

>  	}
> 
>  	for (i = 0; i < num_xstats; i++)
> @@ -63,9 +70,6 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t
> port_id)
>  	if (ret < 0)
>  		METRICS_LOG_ERR("rte_metrics_reg_names failed - metrics
> may already be registered");
> 
> -free_xstats:
> -	free(eth_xstats_names);
> -	free(xstats_names);
Any reason for this change? This is leaking memory in the successful case.

>  	return ret;
>  }
> 
> @@ -167,9 +171,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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH] lib/metrics: fix memory leak
  2020-07-31  3:45 [dpdk-dev] [PATCH] librte_metrics: fix memory leak Gaurav Singh
                   ` (2 preceding siblings ...)
  2020-08-01  6:08 ` Gaurav Singh
@ 2020-08-08 16:39 ` Gaurav Singh
  2020-08-11 21:01   ` Honnappa Nagarahalli
  3 siblings, 1 reply; 10+ messages in thread
From: Gaurav Singh @ 2020-08-08 16:39 UTC (permalink / raw)
  To: dev; +Cc: Gaurav Singh

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] lib/metrics: fix memory leak
  2020-08-08 16:39 ` [dpdk-dev] [PATCH] lib/metrics: " Gaurav Singh
@ 2020-08-11 21:01   ` Honnappa Nagarahalli
  2020-09-22 10:26     ` Power, Ciara
  0 siblings, 1 reply; 10+ messages in thread
From: Honnappa Nagarahalli @ 2020-08-11 21:01 UTC (permalink / raw)
  To: Gaurav Singh, dev; +Cc: nd, Honnappa Nagarahalli, nd

<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>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] lib/metrics: fix memory leak
  2020-08-11 21:01   ` Honnappa Nagarahalli
@ 2020-09-22 10:26     ` Power, Ciara
  2020-10-30 14:59       ` David Marchand
  0 siblings, 1 reply; 10+ messages in thread
From: Power, Ciara @ 2020-09-22 10:26 UTC (permalink / raw)
  To: Honnappa Nagarahalli, Gaurav Singh, dev; +Cc: nd, nd

Hi Gaurav,


>-----Original Message-----
>From: dev <dev-bounces@dpdk.org> On Behalf Of Honnappa Nagarahalli
>Sent: Tuesday 11 August 2020 22:01
>To: Gaurav Singh <gaurav1086@gmail.com>; 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
>
><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(-)


I think this commit message should be more descriptive, and is missing Cc: stable@dpdk.org


>> 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;
>>  	}

Is there a reason for the above changes? I think they are unrelated to 
the memory leak this patch is fixing.

>>  	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;
>>  	}

This does fix the resource leak, but I do think it can be done in a 
simpler way, as shown in the patch I sent to fix the logged coverity issue
for this: https://patchwork.dpdk.org/patch/78052/
I will remove my patch seeing as this patch is fixing the same thing.
 
Thanks,
Ciara

>> --
>> 2.17.1
>
>Looks good.
>Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] lib/metrics: fix memory leak
  2020-09-22 10:26     ` Power, Ciara
@ 2020-10-30 14:59       ` David Marchand
  2020-11-03 21:36         ` David Marchand
  0 siblings, 1 reply; 10+ messages in thread
From: David Marchand @ 2020-10-30 14:59 UTC (permalink / raw)
  To: Gaurav Singh, Power, Ciara; +Cc: Honnappa Nagarahalli, dev, nd

Hello Gaurav,

On Tue, Sep 22, 2020 at 12:27 PM Power, Ciara <ciara.power@intel.com> wrote:
> >-----Original Message-----
> >From: dev <dev-bounces@dpdk.org> On Behalf Of Honnappa Nagarahalli
> >Sent: Tuesday 11 August 2020 22:01
> >To: Gaurav Singh <gaurav1086@gmail.com>; 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
> >
> ><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(-)
>
>
> I think this commit message should be more descriptive, and is missing Cc: stable@dpdk.org
>
>
> >> 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;
> >>      }
>
> Is there a reason for the above changes? I think they are unrelated to
> the memory leak this patch is fixing.
>
> >>      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;
> >>      }
>
> This does fix the resource leak, but I do think it can be done in a
> simpler way, as shown in the patch I sent to fix the logged coverity issue
> for this: https://patchwork.dpdk.org/patch/78052/
> I will remove my patch seeing as this patch is fixing the same thing.

I agree with Ciara.
Could you respin?

Thanks.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH] lib/metrics: fix memory leak
  2020-10-30 14:59       ` David Marchand
@ 2020-11-03 21:36         ` David Marchand
  0 siblings, 0 replies; 10+ messages in thread
From: David Marchand @ 2020-11-03 21:36 UTC (permalink / raw)
  To: Gaurav Singh, Power, Ciara; +Cc: Honnappa Nagarahalli, dev, nd

On Fri, Oct 30, 2020 at 3:59 PM David Marchand
<david.marchand@redhat.com> wrote:
> > This does fix the resource leak, but I do think it can be done in a
> > simpler way, as shown in the patch I sent to fix the logged coverity issue
> > for this: https://patchwork.dpdk.org/patch/78052/
> > I will remove my patch seeing as this patch is fixing the same thing.
>
> I agree with Ciara.
> Could you respin?

I went with Ciara patch as it is minimal and ready to be merged.
Thanks.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-11-03 21:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31  3:45 [dpdk-dev] [PATCH] librte_metrics: fix memory leak 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
2020-09-22 10:26     ` Power, Ciara
2020-10-30 14:59       ` David Marchand
2020-11-03 21:36         ` David Marchand

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).