netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iproute2: prevent memory leak
@ 2023-11-14  9:24 heminhong
  2023-11-15  0:36 ` Stephen Hemminger
  0 siblings, 1 reply; 13+ messages in thread
From: heminhong @ 2023-11-14  9:24 UTC (permalink / raw)
  To: stephen, netdev; +Cc: heminhong

The 'rtnl_talk' allocated memory for 'answer',
in the exception handling branch, memory should be free,
otherwise it will cause memory leak.

Signed-off-by: heminhong <heminhong@kylinos.cn>
---
 ip/link_gre.c    | 4 ++++
 ip/link_gre6.c   | 4 ++++
 ip/link_ip6tnl.c | 4 ++++
 ip/link_iptnl.c  | 4 ++++
 ip/link_vti.c    | 4 ++++
 ip/link_vti6.c   | 4 ++++
 6 files changed, 24 insertions(+)

diff --git a/ip/link_gre.c b/ip/link_gre.c
index 74a5b5e9..b1c49ace 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -111,6 +111,10 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 
 		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
 get_failed:
+			if (NULL != answer)
+			{
+				free(answer);
+			}
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index b03bd65a..64302d63 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -113,6 +113,10 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 
 		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
 get_failed:
+			if (NULL != answer)
+			{
+				free(answer);
+			}
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index b27d696f..16ed6e0d 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -99,6 +99,10 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
 
 		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
 get_failed:
+			if (NULL != answer)
+			{
+				free(answer);
+			}
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index 1315aebe..27326382 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -103,6 +103,10 @@ static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
 
 		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
 get_failed:
+			if (NULL != answer)
+			{
+				free(answer);
+			}
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 50943254..92d5c5ad 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -67,6 +67,10 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
 
 		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
 get_failed:
+			if (NULL != answer)
+			{
+				free(answer);
+			}
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index 5764221e..b50158fe 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -69,6 +69,10 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
 
 		if (rtnl_talk(&rth, &req.n, &answer) < 0) {
 get_failed:
+			if (NULL != answer)
+			{
+				free(answer);
+			}
 			fprintf(stderr,
 				"Failed to get existing tunnel info.\n");
 			return -1;
-- 
2.25.1


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

end of thread, other threads:[~2023-11-17 17:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-14  9:24 [PATCH] iproute2: prevent memory leak heminhong
2023-11-15  0:36 ` Stephen Hemminger
2023-11-15  2:37   ` [PATCH v2] " heminhong
2023-11-15  3:32     ` Florian Westphal
2023-11-15  3:33     ` Stephen Hemminger
2023-11-15  7:56       ` [PATCH v3] " heminhong
2023-11-15 10:23         ` Petr Machata
2023-11-16  3:13           ` [PATCH v4] " heminhong
2023-11-16 12:04             ` Andrea Claudi
2023-11-16 23:05             ` Stephen Hemminger
2023-11-17  0:45               ` Andrea Claudi
2023-11-17  3:31                 ` Stephen Hemminger
2023-11-17 17:20             ` patchwork-bot+netdevbpf

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