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

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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git