DPDK patches and discussions
 help / color / mirror / Atom feed
From: Radu Nicolau <radu.nicolau@intel.com>
To: Radu Nicolau <radu.nicolau@intel.com>, Akhil Goyal <gakhil@marvell.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH] examples/ipsec-secgw: fix memory leaks
Date: Tue,  9 Nov 2021 09:51:40 +0000	[thread overview]
Message-ID: <20211109095140.3888643-1-radu.nicolau@intel.com> (raw)

Free telemetry structures when memory allocation
or input parameter errors occur.
Fixes: 3e7b7dd88021 ("examples/ipsec-secgw: support telemetry")

Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
 examples/ipsec-secgw/ipsec-secgw.c | 65 ++++++++++++++++++++++--------
 1 file changed, 49 insertions(+), 16 deletions(-)

diff --git a/examples/ipsec-secgw/ipsec-secgw.c b/examples/ipsec-secgw/ipsec-secgw.c
index 0a1c5bcaaa..564d7981e5 100644
--- a/examples/ipsec-secgw/ipsec-secgw.c
+++ b/examples/ipsec-secgw/ipsec-secgw.c
@@ -3025,12 +3025,14 @@ handle_telemetry_cmd_ipsec_secgw_stats_outbound(const char *cmd __rte_unused,
 	struct rte_tel_data *spd4_data = rte_tel_data_alloc();
 	struct rte_tel_data *spd6_data = rte_tel_data_alloc();
 	struct rte_tel_data *sad_data = rte_tel_data_alloc();
-
 	unsigned int coreid = UINT32_MAX;
+	int rc = 0;
 
 	/* verify allocated telemetry data structures */
-	if (!spd4_data || !spd6_data || !sad_data)
-		return -ENOMEM;
+	if (!spd4_data || !spd6_data || !sad_data) {
+		rc = -ENOMEM;
+		goto exit;
+	}
 
 	/* initialize telemetry data structs as dicts */
 	rte_tel_data_start_dict(data);
@@ -3041,8 +3043,10 @@ handle_telemetry_cmd_ipsec_secgw_stats_outbound(const char *cmd __rte_unused,
 
 	if (params) {
 		coreid = (uint32_t)atoi(params);
-		if (rte_lcore_is_enabled(coreid) == 0)
-			return -EINVAL;
+		if (rte_lcore_is_enabled(coreid) == 0) {
+			rc = -EINVAL;
+			goto exit;
+		}
 	}
 
 	update_statistics(&total_stats, coreid);
@@ -3076,7 +3080,13 @@ handle_telemetry_cmd_ipsec_secgw_stats_outbound(const char *cmd __rte_unused,
 
 	rte_tel_data_add_dict_container(data, "sad", sad_data, 0);
 
-	return 0;
+exit:
+	if (rc) {
+		rte_tel_data_free(spd4_data);
+		rte_tel_data_free(spd6_data);
+		rte_tel_data_free(sad_data);
+	}
+	return rc;
 }
 
 static int
@@ -3088,12 +3098,14 @@ handle_telemetry_cmd_ipsec_secgw_stats_inbound(const char *cmd __rte_unused,
 	struct rte_tel_data *spd4_data = rte_tel_data_alloc();
 	struct rte_tel_data *spd6_data = rte_tel_data_alloc();
 	struct rte_tel_data *sad_data = rte_tel_data_alloc();
-
 	unsigned int coreid = UINT32_MAX;
+	int rc = 0;
 
 	/* verify allocated telemetry data structures */
-	if (!spd4_data || !spd6_data || !sad_data)
-		return -ENOMEM;
+	if (!spd4_data || !spd6_data || !sad_data) {
+		rc = -ENOMEM;
+		goto exit;
+	}
 
 	/* initialize telemetry data structs as dicts */
 	rte_tel_data_start_dict(data);
@@ -3105,8 +3117,10 @@ handle_telemetry_cmd_ipsec_secgw_stats_inbound(const char *cmd __rte_unused,
 
 	if (params) {
 		coreid = (uint32_t)atoi(params);
-		if (rte_lcore_is_enabled(coreid) == 0)
-			return -EINVAL;
+		if (rte_lcore_is_enabled(coreid) == 0) {
+			rc = -EINVAL;
+			goto exit;
+		}
 	}
 
 	update_statistics(&total_stats, coreid);
@@ -3140,7 +3154,13 @@ handle_telemetry_cmd_ipsec_secgw_stats_inbound(const char *cmd __rte_unused,
 
 	rte_tel_data_add_dict_container(data, "spd6", spd6_data, 0);
 
-	return 0;
+exit:
+	if (rc) {
+		rte_tel_data_free(spd4_data);
+		rte_tel_data_free(spd6_data);
+		rte_tel_data_free(sad_data);
+	}
+	return rc;
 }
 
 static int
@@ -3151,8 +3171,14 @@ handle_telemetry_cmd_ipsec_secgw_stats_routing(const char *cmd __rte_unused,
 
 	struct rte_tel_data *lpm4_data = rte_tel_data_alloc();
 	struct rte_tel_data *lpm6_data = rte_tel_data_alloc();
-
 	unsigned int coreid = UINT32_MAX;
+	int rc = 0;
+
+	/* verify allocated telemetry data structures */
+	if (!lpm4_data || !lpm6_data) {
+		rc = -ENOMEM;
+		goto exit;
+	}
 
 	/* initialize telemetry data structs as dicts */
 	rte_tel_data_start_dict(data);
@@ -3162,8 +3188,10 @@ handle_telemetry_cmd_ipsec_secgw_stats_routing(const char *cmd __rte_unused,
 
 	if (params) {
 		coreid = (uint32_t)atoi(params);
-		if (rte_lcore_is_enabled(coreid) == 0)
-			return -EINVAL;
+		if (rte_lcore_is_enabled(coreid) == 0) {
+			rc = -EINVAL;
+			goto exit;
+		}
 	}
 
 	update_statistics(&total_stats, coreid);
@@ -3180,7 +3208,12 @@ handle_telemetry_cmd_ipsec_secgw_stats_routing(const char *cmd __rte_unused,
 
 	rte_tel_data_add_dict_container(data, "IPv6 LPM", lpm6_data, 0);
 
-	return 0;
+exit:
+	if (rc) {
+		rte_tel_data_free(lpm4_data);
+		rte_tel_data_free(lpm6_data);
+	}
+	return rc;
 }
 
 static void
-- 
2.25.1


             reply	other threads:[~2021-11-09 10:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-09  9:51 Radu Nicolau [this message]
2021-11-11 11:21 ` [EXT] " Akhil Goyal

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=20211109095140.3888643-1-radu.nicolau@intel.com \
    --to=radu.nicolau@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.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).