]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iproute2: prevent memory leak
authorheminhong <heminhong@kylinos.cn>
Thu, 16 Nov 2023 03:13:08 +0000 (11:13 +0800)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 17 Nov 2023 16:41:43 +0000 (08:41 -0800)
When the return value of rtnl_talk() is not less than 0,
'answer' will be allocated. The 'answer' should be free
after using, otherwise it will cause memory leak.

Fixes: a066cc6623e1 ("gre/gre6: Unify local/remote endpoint address parsing")
Signed-off-by: heminhong <heminhong@kylinos.cn>
Reviewed-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/link_gre.c
ip/link_gre6.c
ip/link_ip6tnl.c
ip/link_iptnl.c
ip/link_vti.c
ip/link_vti6.c

index 74a5b5e9652aee3289989340f846ef9b30745e2e..6d71864c1999559750dbce60526ef0aca83c264d 100644 (file)
@@ -76,7 +76,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
                .i.ifi_family = preferred_family,
                .i.ifi_index = ifi->ifi_index,
        };
-       struct nlmsghdr *answer;
+       struct nlmsghdr *answer = NULL;
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct rtattr *greinfo[IFLA_GRE_MAX + 1];
@@ -113,6 +113,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 get_failed:
                        fprintf(stderr,
                                "Failed to get existing tunnel info.\n");
+                       free(answer);
                        return -1;
                }
 
index b03bd65adb53edaeadd8ff612245865a1c0343c6..4d1c657488c45cee589d499285dd2826efe91f00 100644 (file)
@@ -79,7 +79,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
                .i.ifi_family = preferred_family,
                .i.ifi_index = ifi->ifi_index,
        };
-       struct nlmsghdr *answer;
+       struct nlmsghdr *answer = NULL;
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct rtattr *greinfo[IFLA_GRE_MAX + 1];
@@ -115,6 +115,7 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
 get_failed:
                        fprintf(stderr,
                                "Failed to get existing tunnel info.\n");
+                       free(answer);
                        return -1;
                }
 
index b27d696f565a1deaba758ca9fe10afc53b272faf..3a30dca9398068681e378b3f90d5dafc22c59bae 100644 (file)
@@ -72,7 +72,7 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
                .i.ifi_family = preferred_family,
                .i.ifi_index = ifi->ifi_index,
        };
-       struct nlmsghdr *answer;
+       struct nlmsghdr *answer = NULL;
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1];
@@ -101,6 +101,7 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
 get_failed:
                        fprintf(stderr,
                                "Failed to get existing tunnel info.\n");
+                       free(answer);
                        return -1;
                }
 
index 1315aebe93f257c98770832cbf16ae1e56851d4d..879202f71155c42a72467061830bb3ab8383c5c0 100644 (file)
@@ -73,7 +73,7 @@ static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
                .i.ifi_family = preferred_family,
                .i.ifi_index = ifi->ifi_index,
        };
-       struct nlmsghdr *answer;
+       struct nlmsghdr *answer = NULL;
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct rtattr *iptuninfo[IFLA_IPTUN_MAX + 1];
@@ -105,6 +105,7 @@ static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
 get_failed:
                        fprintf(stderr,
                                "Failed to get existing tunnel info.\n");
+                       free(answer);
                        return -1;
                }
 
index 509432543fc5384ec101b46cc644303e82c6c6b5..7a95dc02dc08d1de184c0ef44dafbf41b003149b 100644 (file)
@@ -48,7 +48,7 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
                .i.ifi_family = preferred_family,
                .i.ifi_index = ifi->ifi_index,
        };
-       struct nlmsghdr *answer;
+       struct nlmsghdr *answer = NULL;
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
@@ -69,6 +69,7 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
 get_failed:
                        fprintf(stderr,
                                "Failed to get existing tunnel info.\n");
+                       free(answer);
                        return -1;
                }
 
index 5764221ebb89191192b078d6936e261ffb3869d8..aaf701d332989a7893d620a023f52346749fab52 100644 (file)
@@ -50,7 +50,7 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
                .i.ifi_family = preferred_family,
                .i.ifi_index = ifi->ifi_index,
        };
-       struct nlmsghdr *answer;
+       struct nlmsghdr *answer = NULL;
        struct rtattr *tb[IFLA_MAX + 1];
        struct rtattr *linkinfo[IFLA_INFO_MAX+1];
        struct rtattr *vtiinfo[IFLA_VTI_MAX + 1];
@@ -71,6 +71,7 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
 get_failed:
                        fprintf(stderr,
                                "Failed to get existing tunnel info.\n");
+                       free(answer);
                        return -1;
                }