* [dpdk-dev] [PATCH] examples/ipsec-secgw: fix memory leaks
@ 2021-11-09 9:51 Radu Nicolau
2021-11-11 11:21 ` [EXT] " Akhil Goyal
0 siblings, 1 reply; 2+ messages in thread
From: Radu Nicolau @ 2021-11-09 9:51 UTC (permalink / raw)
To: Radu Nicolau, Akhil Goyal; +Cc: dev
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [EXT] [PATCH] examples/ipsec-secgw: fix memory leaks
2021-11-09 9:51 [dpdk-dev] [PATCH] examples/ipsec-secgw: fix memory leaks Radu Nicolau
@ 2021-11-11 11:21 ` Akhil Goyal
0 siblings, 0 replies; 2+ messages in thread
From: Akhil Goyal @ 2021-11-11 11:21 UTC (permalink / raw)
To: Radu Nicolau; +Cc: dev
> 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>
> ---
Acked-by: Akhil Goyal <gakhil@marvell.com>
Applied to dpdk-next-crypto
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-11 11:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 9:51 [dpdk-dev] [PATCH] examples/ipsec-secgw: fix memory leaks Radu Nicolau
2021-11-11 11:21 ` [EXT] " Akhil Goyal
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).