Skip to contentSkip to conversation

metrics: fix resource leak on memory allocation fail

PATCH Applied Ciara Power 4 participants 5 messages Sep 17, 2020 – Nov 3, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 metrics: fix resource leak on memory allocation fail

If an error occurred when allocating memory for metrics or names, the function returned without freeing allocated memory. This is now fixed to avoid the resource leak in the case that either metrics or names had been successfully allocated memory.

Coverity issue: 362053

Fixes c5b7197f662e ("telemetry: move some functions to metrics library")
---
 lib/librte_metrics/rte_metrics_telemetry.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_metrics/rte_metrics_telemetry.c +2 -1
index 289ebae0bd..36a3821b4c 100644
@@ -170,7 +170,8 @@ rte_metrics_tel_format_port(uint32_t pid, json_t *ports,
 	names = malloc(sizeof(struct rte_metric_name) * num_metrics);
 	if (metrics == NULL || names == NULL) {
 		METRICS_LOG_ERR("Cannot allocate memory");
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto fail;
 	}
 
 	if (rte_metrics_get_names(names, num_metrics) != num_metrics ||
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines

If an error occurred when allocating memory for metrics or names, the function returned without freeing allocated memory. This is now fixed to avoid the resource leak in the case that either metrics or names had been successfully allocated memory.

Coverity issue: 362053

Fixes c5b7197f662e ("telemetry: move some functions to metrics library")
#2 lore raw

<snip>

Quoted 6 lines
Quoted 6 lines

If an error occurred when allocating memory for metrics or names, the function returned without freeing allocated memory. This is now fixed to avoid the resource leak in the case that either metrics or names had been successfully allocated memory.

Quoted 7 lines
Quoted 4 lines

Coverity issue: 362053

Fixes c5b7197f662e ("telemetry: move some functions to metrics

library")
Cc: [email protected]

This is fixed in https://patches.dpdk.org/patch/75323/. Can you please check if that suffices?

#3 lore raw

Hi Honnappa,

Quoted 24 lines

-----Original Message-----
From: Honnappa Nagarahalli <[email protected]>
Sent: Tuesday 22 September 2020 00:43
To: Mcnamara, John <[email protected]>; Power, Ciara <[email protected]>; [email protected]
Cc: Power, Ciara <[email protected]>; [email protected]; Wiles, Keith <[email protected]>; nd <[email protected]>; Honnappa Nagarahalli <[email protected]>; nd <[email protected]>
Subject: RE: [dpdk-dev] [dpdk-stable] [PATCH] metrics: fix resource leak on memory allocation fail

<snip>

Quoted 11 lines
Quoted 10 lines

If an error occurred when allocating memory for metrics or names, the function returned without freeing allocated memory. This is now fixed to avoid the resource leak in the case that either metrics or names had been successfully allocated memory.

Coverity issue: 362053

Fixes c5b7197f662e ("telemetry: move some functions to metrics

library")
Cc: [email protected]

Quoted 4 lines
Quoted 2 lines

This is fixed in https://patches.dpdk.org/patch/75323/. Can you please check if that suffices?

I left some comments on that patch, but seeing as it is fixing the same issue, I will remove this patch.

Thanks,
Ciara

Acked-by John McNamara on v1 1/1 Applied
#4 lore raw
In reply to Ciara Power
Quoted 10 lines · Ciara Power

If an error occurred when allocating memory for metrics or names, the function returned without freeing allocated memory. This is now fixed to avoid the resource leak in the case that either metrics or names had been successfully allocated memory.

Coverity issue: 362053

Fixes c5b7197f662e ("telemetry: move some functions to metrics library")

Gaurav reported the same issue and proposed a patch, but I went with yours as it describes the issue, is minimal and has the proper tags for backport.

Quoted 1 line

Applied, thanks.

Signature · 1 line
David Marchand