* [PATCH] ipruote2: optimize code and fix some mem-leak risk
@ 2023-05-10 13:36 zhaoshuang
2023-05-10 13:55 ` Pawel Chmielewski
` (6 more replies)
0 siblings, 7 replies; 13+ messages in thread
From: zhaoshuang @ 2023-05-10 13:36 UTC (permalink / raw)
To: netdev
From: zhaoshuang <zhaoshuang@uniontech.com>
Signed-off-by: zhaoshuang <zhaoshuang@uniontech.com>
Signed-off-by: zhaoshuang <izhaoshuang@163.com>
---
bridge/mdb.c | 4 ++++
devlink/devlink.c | 21 +++++++++------------
ip/ipaddrlabel.c | 1 +
ip/ipfou.c | 1 +
ip/ipila.c | 1 +
ip/ipnetconf.c | 1 +
ip/ipnexthop.c | 4 ++++
ip/iproute.c | 6 ++++++
ip/iprule.c | 1 +
ip/iptuntap.c | 1 +
ip/tunnel.c | 2 ++
tc/tc_class.c | 1 +
tc/tc_filter.c | 1 +
tc/tc_qdisc.c | 1 +
14 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/bridge/mdb.c b/bridge/mdb.c
index dcc08235..fbb4f704 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -466,12 +466,14 @@ static int mdb_show(int argc, char **argv)
/* get mdb entries */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_array(PRINT_JSON, "mdb");
if (rtnl_dump_filter(&rth, print_mdbs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_array(PRINT_JSON, NULL);
@@ -479,12 +481,14 @@ static int mdb_show(int argc, char **argv)
/* get router ports */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_object("router");
if (rtnl_dump_filter(&rth, print_rtrs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_object();
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 019ffc23..26513142 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -205,6 +205,14 @@ struct ifname_map {
char *ifname;
};
+static void ifname_map_free(struct ifname_map *ifname_map)
+{
+ free(ifname_map->ifname);
+ free(ifname_map->dev_name);
+ free(ifname_map->bus_name);
+ free(ifname_map);
+}
+
static struct ifname_map *ifname_map_alloc(const char *bus_name,
const char *dev_name,
uint32_t port_index,
@@ -221,23 +229,12 @@ static struct ifname_map *ifname_map_alloc(const char *bus_name,
ifname_map->ifname = strdup(ifname);
if (!ifname_map->bus_name || !ifname_map->dev_name ||
!ifname_map->ifname) {
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
+ ifname_map_free(ifname_map);
return NULL;
}
return ifname_map;
}
-static void ifname_map_free(struct ifname_map *ifname_map)
-{
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
-}
-
static int ifname_map_update(struct ifname_map *ifname_map, const char *ifname)
{
char *new_ifname;
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index 46f68c41..b045827a 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -113,6 +113,7 @@ static int ipaddrlabel_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_addrlabel, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipfou.c b/ip/ipfou.c
index ed99a548..760cfee2 100644
--- a/ip/ipfou.c
+++ b/ip/ipfou.c
@@ -318,6 +318,7 @@ static int do_show(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_fou_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipila.c b/ip/ipila.c
index 335d15f6..4f6d578f 100644
--- a/ip/ipila.c
+++ b/ip/ipila.c
@@ -150,6 +150,7 @@ static int do_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_ila_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 7ddaefb4..9ae6c45e 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -209,6 +209,7 @@ dump:
*/
if (errno == EOPNOTSUPP &&
filter.family == AF_UNSPEC) {
+ delete_json_obj();
filter.family = AF_INET;
goto dump;
}
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 9f16b809..abbf4d45 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -1021,6 +1021,7 @@ static int ipnh_get_id(__u32 id)
new_json_obj(json);
if (print_nexthop_nocache(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
@@ -1106,6 +1107,7 @@ static int ipnh_list_flush(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_nocache, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1181,6 +1183,7 @@ static int ipnh_bucket_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_bucket, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1221,6 +1224,7 @@ static int ipnh_bucket_get_id(__u32 id, __u16 bucket_index)
new_json_obj(json);
if (print_nexthop_bucket(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iproute.c b/ip/iproute.c
index a7cd9543..7909c4a2 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1977,6 +1977,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if (rtnl_dump_filter_errhndlr(&rth, filter_fn, stdout,
save_route_errhndlr, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -2;
}
@@ -2172,18 +2173,21 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
if (answer->nlmsg_type != RTM_NEWROUTE) {
fprintf(stderr, "Not a route?\n");
+ delete_json_obj();
free(answer);
return -1;
}
len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0) {
fprintf(stderr, "Wrong len %d\n", len);
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2195,6 +2199,7 @@ static int iproute_get(int argc, char **argv)
r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]);
} else if (!tb[RTA_SRC]) {
fprintf(stderr, "Failed to connect the route\n");
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2217,6 +2222,7 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iprule.c b/ip/iprule.c
index 458607ef..e503e5c6 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -714,6 +714,7 @@ static int iprule_list_flush_or_save(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index ab7d5d87..552599e9 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -441,6 +441,7 @@ static int do_show(int argc, char **argv)
if (rtnl_dump_filter(&rth, print_tuntap, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 75cb0b51..c5c7a31f 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -419,11 +419,13 @@ int do_tunnels_list(struct tnl_print_nlmsg_info *info)
new_json_obj(json);
if (rtnl_linkdump_req(&rth, preferred_family) < 0) {
perror("Cannot send dump request\n");
+ delete_json_obj();
return -1;
}
if (rtnl_dump_filter(&rth, print_nlmsg_tunnel, info) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
delete_json_obj();
diff --git a/tc/tc_class.c b/tc/tc_class.c
index 096fa2ec..65776180 100644
--- a/tc/tc_class.c
+++ b/tc/tc_class.c
@@ -453,6 +453,7 @@ static int tc_class_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_class, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index 700a09f6..12a21433 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -734,6 +734,7 @@ static int tc_filter_list(int cmd, int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_filter, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index 92ceb4c2..b137517b 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -433,6 +433,7 @@ static int tc_qdisc_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_qdisc, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] ipruote2: optimize code and fix some mem-leak risk
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
@ 2023-05-10 13:55 ` Pawel Chmielewski
2023-05-10 13:59 ` Pawel Chmielewski
2023-05-10 15:24 ` [PATCH] iproute2: " zhaoshuang
` (5 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Pawel Chmielewski @ 2023-05-10 13:55 UTC (permalink / raw)
To: zhaoshuang; +Cc: netdev
On Wed, May 10, 2023 at 09:36:16PM +0800, zhaoshuang wrote:
> From: zhaoshuang <zhaoshuang@uniontech.com>
>
> Signed-off-by: zhaoshuang <zhaoshuang@uniontech.com>
> Signed-off-by: zhaoshuang <izhaoshuang@163.com>
> ---
Looks good to me
Reviewed-by: Pawel Chmielewski <pawel.chmielewski@intel.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] ipruote2: optimize code and fix some mem-leak risk
2023-05-10 13:55 ` Pawel Chmielewski
@ 2023-05-10 13:59 ` Pawel Chmielewski
0 siblings, 0 replies; 13+ messages in thread
From: Pawel Chmielewski @ 2023-05-10 13:59 UTC (permalink / raw)
To: zhaoshuang; +Cc: netdev
On Wed, May 10, 2023 at 03:55:02PM +0200, Pawel Chmielewski wrote:
> On Wed, May 10, 2023 at 09:36:16PM +0800, zhaoshuang wrote:
> > From: zhaoshuang <zhaoshuang@uniontech.com>
> >
> > Signed-off-by: zhaoshuang <zhaoshuang@uniontech.com>
> > Signed-off-by: zhaoshuang <izhaoshuang@163.com>
> > ---
>
> Looks good to me
>
> Reviewed-by: Pawel Chmielewski <pawel.chmielewski@intel.com>
>
I forgot - please change "ipruote2" to "iproute2"
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] iproute2: optimize code and fix some mem-leak risk
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
2023-05-10 13:55 ` Pawel Chmielewski
@ 2023-05-10 15:24 ` zhaoshuang
2023-05-10 15:47 ` [PATCH] ipruote2: " zhaoshuang
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: zhaoshuang @ 2023-05-10 15:24 UTC (permalink / raw)
To: netdev
From: zhaoshuang <zhaoshuang@uniontech.com>
Signed-off-by: zhaoshuang <zhaoshuang@uniontech.com>
Signed-off-by: zhaoshuang <izhaoshuang@163.com>
---
bridge/mdb.c | 4 ++++
devlink/devlink.c | 21 +++++++++------------
ip/ipaddrlabel.c | 1 +
ip/ipfou.c | 1 +
ip/ipila.c | 1 +
ip/ipnetconf.c | 1 +
ip/ipnexthop.c | 4 ++++
ip/iproute.c | 6 ++++++
ip/iprule.c | 1 +
ip/iptuntap.c | 1 +
ip/tunnel.c | 2 ++
tc/tc_class.c | 1 +
tc/tc_filter.c | 1 +
tc/tc_qdisc.c | 1 +
14 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/bridge/mdb.c b/bridge/mdb.c
index dcc08235..fbb4f704 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -466,12 +466,14 @@ static int mdb_show(int argc, char **argv)
/* get mdb entries */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_array(PRINT_JSON, "mdb");
if (rtnl_dump_filter(&rth, print_mdbs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_array(PRINT_JSON, NULL);
@@ -479,12 +481,14 @@ static int mdb_show(int argc, char **argv)
/* get router ports */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_object("router");
if (rtnl_dump_filter(&rth, print_rtrs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_object();
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 019ffc23..26513142 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -205,6 +205,14 @@ struct ifname_map {
char *ifname;
};
+static void ifname_map_free(struct ifname_map *ifname_map)
+{
+ free(ifname_map->ifname);
+ free(ifname_map->dev_name);
+ free(ifname_map->bus_name);
+ free(ifname_map);
+}
+
static struct ifname_map *ifname_map_alloc(const char *bus_name,
const char *dev_name,
uint32_t port_index,
@@ -221,23 +229,12 @@ static struct ifname_map *ifname_map_alloc(const char *bus_name,
ifname_map->ifname = strdup(ifname);
if (!ifname_map->bus_name || !ifname_map->dev_name ||
!ifname_map->ifname) {
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
+ ifname_map_free(ifname_map);
return NULL;
}
return ifname_map;
}
-static void ifname_map_free(struct ifname_map *ifname_map)
-{
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
-}
-
static int ifname_map_update(struct ifname_map *ifname_map, const char *ifname)
{
char *new_ifname;
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index 46f68c41..b045827a 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -113,6 +113,7 @@ static int ipaddrlabel_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_addrlabel, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipfou.c b/ip/ipfou.c
index ed99a548..760cfee2 100644
--- a/ip/ipfou.c
+++ b/ip/ipfou.c
@@ -318,6 +318,7 @@ static int do_show(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_fou_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipila.c b/ip/ipila.c
index 335d15f6..4f6d578f 100644
--- a/ip/ipila.c
+++ b/ip/ipila.c
@@ -150,6 +150,7 @@ static int do_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_ila_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 7ddaefb4..9ae6c45e 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -209,6 +209,7 @@ dump:
*/
if (errno == EOPNOTSUPP &&
filter.family == AF_UNSPEC) {
+ delete_json_obj();
filter.family = AF_INET;
goto dump;
}
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 9f16b809..abbf4d45 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -1021,6 +1021,7 @@ static int ipnh_get_id(__u32 id)
new_json_obj(json);
if (print_nexthop_nocache(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
@@ -1106,6 +1107,7 @@ static int ipnh_list_flush(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_nocache, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1181,6 +1183,7 @@ static int ipnh_bucket_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_bucket, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1221,6 +1224,7 @@ static int ipnh_bucket_get_id(__u32 id, __u16 bucket_index)
new_json_obj(json);
if (print_nexthop_bucket(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iproute.c b/ip/iproute.c
index a7cd9543..7909c4a2 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1977,6 +1977,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if (rtnl_dump_filter_errhndlr(&rth, filter_fn, stdout,
save_route_errhndlr, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -2;
}
@@ -2172,18 +2173,21 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
if (answer->nlmsg_type != RTM_NEWROUTE) {
fprintf(stderr, "Not a route?\n");
+ delete_json_obj();
free(answer);
return -1;
}
len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0) {
fprintf(stderr, "Wrong len %d\n", len);
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2195,6 +2199,7 @@ static int iproute_get(int argc, char **argv)
r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]);
} else if (!tb[RTA_SRC]) {
fprintf(stderr, "Failed to connect the route\n");
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2217,6 +2222,7 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iprule.c b/ip/iprule.c
index 458607ef..e503e5c6 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -714,6 +714,7 @@ static int iprule_list_flush_or_save(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index ab7d5d87..552599e9 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -441,6 +441,7 @@ static int do_show(int argc, char **argv)
if (rtnl_dump_filter(&rth, print_tuntap, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 75cb0b51..c5c7a31f 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -419,11 +419,13 @@ int do_tunnels_list(struct tnl_print_nlmsg_info *info)
new_json_obj(json);
if (rtnl_linkdump_req(&rth, preferred_family) < 0) {
perror("Cannot send dump request\n");
+ delete_json_obj();
return -1;
}
if (rtnl_dump_filter(&rth, print_nlmsg_tunnel, info) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
delete_json_obj();
diff --git a/tc/tc_class.c b/tc/tc_class.c
index 096fa2ec..65776180 100644
--- a/tc/tc_class.c
+++ b/tc/tc_class.c
@@ -453,6 +453,7 @@ static int tc_class_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_class, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index 700a09f6..12a21433 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -734,6 +734,7 @@ static int tc_filter_list(int cmd, int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_filter, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index 92ceb4c2..b137517b 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -433,6 +433,7 @@ static int tc_qdisc_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_qdisc, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] ipruote2: optimize code and fix some mem-leak risk
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
2023-05-10 13:55 ` Pawel Chmielewski
2023-05-10 15:24 ` [PATCH] iproute2: " zhaoshuang
@ 2023-05-10 15:47 ` zhaoshuang
2023-05-10 15:47 ` [PATCH] iproute2: " zhaoshuang
` (3 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: zhaoshuang @ 2023-05-10 15:47 UTC (permalink / raw)
To: pawel.chmielewski; +Cc: netdev
@pawel.chmielewski
Thanks for your review
The commit message has been modified. But I don't know how to modify mail subject
If the mail subject shall be corrected, could U help to do it? Thanks
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] iproute2: optimize code and fix some mem-leak risk
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
` (2 preceding siblings ...)
2023-05-10 15:47 ` [PATCH] ipruote2: " zhaoshuang
@ 2023-05-10 15:47 ` zhaoshuang
2023-05-10 20:39 ` Stephen Hemminger
2023-05-11 0:37 ` [PATCH] ipruote2: " zhaoshuang
` (2 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: zhaoshuang @ 2023-05-10 15:47 UTC (permalink / raw)
To: pawel.chmielewski; +Cc: netdev
From: zhaoshuang <zhaoshuang@uniontech.com>
Signed-off-by: zhaoshuang <zhaoshuang@uniontech.com>
Signed-off-by: zhaoshuang <izhaoshuang@163.com>
---
bridge/mdb.c | 4 ++++
devlink/devlink.c | 21 +++++++++------------
ip/ipaddrlabel.c | 1 +
ip/ipfou.c | 1 +
ip/ipila.c | 1 +
ip/ipnetconf.c | 1 +
ip/ipnexthop.c | 4 ++++
ip/iproute.c | 6 ++++++
ip/iprule.c | 1 +
ip/iptuntap.c | 1 +
ip/tunnel.c | 2 ++
tc/tc_class.c | 1 +
tc/tc_filter.c | 1 +
tc/tc_qdisc.c | 1 +
14 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/bridge/mdb.c b/bridge/mdb.c
index dcc08235..fbb4f704 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -466,12 +466,14 @@ static int mdb_show(int argc, char **argv)
/* get mdb entries */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_array(PRINT_JSON, "mdb");
if (rtnl_dump_filter(&rth, print_mdbs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_array(PRINT_JSON, NULL);
@@ -479,12 +481,14 @@ static int mdb_show(int argc, char **argv)
/* get router ports */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_object("router");
if (rtnl_dump_filter(&rth, print_rtrs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_object();
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 019ffc23..26513142 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -205,6 +205,14 @@ struct ifname_map {
char *ifname;
};
+static void ifname_map_free(struct ifname_map *ifname_map)
+{
+ free(ifname_map->ifname);
+ free(ifname_map->dev_name);
+ free(ifname_map->bus_name);
+ free(ifname_map);
+}
+
static struct ifname_map *ifname_map_alloc(const char *bus_name,
const char *dev_name,
uint32_t port_index,
@@ -221,23 +229,12 @@ static struct ifname_map *ifname_map_alloc(const char *bus_name,
ifname_map->ifname = strdup(ifname);
if (!ifname_map->bus_name || !ifname_map->dev_name ||
!ifname_map->ifname) {
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
+ ifname_map_free(ifname_map);
return NULL;
}
return ifname_map;
}
-static void ifname_map_free(struct ifname_map *ifname_map)
-{
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
-}
-
static int ifname_map_update(struct ifname_map *ifname_map, const char *ifname)
{
char *new_ifname;
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index 46f68c41..b045827a 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -113,6 +113,7 @@ static int ipaddrlabel_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_addrlabel, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipfou.c b/ip/ipfou.c
index ed99a548..760cfee2 100644
--- a/ip/ipfou.c
+++ b/ip/ipfou.c
@@ -318,6 +318,7 @@ static int do_show(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_fou_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipila.c b/ip/ipila.c
index 335d15f6..4f6d578f 100644
--- a/ip/ipila.c
+++ b/ip/ipila.c
@@ -150,6 +150,7 @@ static int do_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_ila_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 7ddaefb4..9ae6c45e 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -209,6 +209,7 @@ dump:
*/
if (errno == EOPNOTSUPP &&
filter.family == AF_UNSPEC) {
+ delete_json_obj();
filter.family = AF_INET;
goto dump;
}
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 9f16b809..abbf4d45 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -1021,6 +1021,7 @@ static int ipnh_get_id(__u32 id)
new_json_obj(json);
if (print_nexthop_nocache(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
@@ -1106,6 +1107,7 @@ static int ipnh_list_flush(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_nocache, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1181,6 +1183,7 @@ static int ipnh_bucket_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_bucket, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1221,6 +1224,7 @@ static int ipnh_bucket_get_id(__u32 id, __u16 bucket_index)
new_json_obj(json);
if (print_nexthop_bucket(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iproute.c b/ip/iproute.c
index a7cd9543..7909c4a2 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1977,6 +1977,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if (rtnl_dump_filter_errhndlr(&rth, filter_fn, stdout,
save_route_errhndlr, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -2;
}
@@ -2172,18 +2173,21 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
if (answer->nlmsg_type != RTM_NEWROUTE) {
fprintf(stderr, "Not a route?\n");
+ delete_json_obj();
free(answer);
return -1;
}
len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0) {
fprintf(stderr, "Wrong len %d\n", len);
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2195,6 +2199,7 @@ static int iproute_get(int argc, char **argv)
r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]);
} else if (!tb[RTA_SRC]) {
fprintf(stderr, "Failed to connect the route\n");
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2217,6 +2222,7 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iprule.c b/ip/iprule.c
index 458607ef..e503e5c6 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -714,6 +714,7 @@ static int iprule_list_flush_or_save(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index ab7d5d87..552599e9 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -441,6 +441,7 @@ static int do_show(int argc, char **argv)
if (rtnl_dump_filter(&rth, print_tuntap, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 75cb0b51..c5c7a31f 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -419,11 +419,13 @@ int do_tunnels_list(struct tnl_print_nlmsg_info *info)
new_json_obj(json);
if (rtnl_linkdump_req(&rth, preferred_family) < 0) {
perror("Cannot send dump request\n");
+ delete_json_obj();
return -1;
}
if (rtnl_dump_filter(&rth, print_nlmsg_tunnel, info) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
delete_json_obj();
diff --git a/tc/tc_class.c b/tc/tc_class.c
index 096fa2ec..65776180 100644
--- a/tc/tc_class.c
+++ b/tc/tc_class.c
@@ -453,6 +453,7 @@ static int tc_class_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_class, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index 700a09f6..12a21433 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -734,6 +734,7 @@ static int tc_filter_list(int cmd, int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_filter, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index 92ceb4c2..b137517b 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -433,6 +433,7 @@ static int tc_qdisc_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_qdisc, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] iproute2: optimize code and fix some mem-leak risk
2023-05-10 15:47 ` [PATCH] iproute2: " zhaoshuang
@ 2023-05-10 20:39 ` Stephen Hemminger
0 siblings, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2023-05-10 20:39 UTC (permalink / raw)
To: zhaoshuang; +Cc: pawel.chmielewski, netdev
On Wed, 10 May 2023 23:47:47 +0800
zhaoshuang <izhaoshuang@163.com> wrote:
> From: zhaoshuang <zhaoshuang@uniontech.com>
>
> Signed-off-by: zhaoshuang <zhaoshuang@uniontech.com>
> Signed-off-by: zhaoshuang <izhaoshuang@163.com>
Best to have a single signoff? I assume these are just two
mail accounts for the same person.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] ipruote2: optimize code and fix some mem-leak risk
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
` (3 preceding siblings ...)
2023-05-10 15:47 ` [PATCH] iproute2: " zhaoshuang
@ 2023-05-11 0:37 ` zhaoshuang
2023-05-11 0:37 ` [PATCH] iproute2: " zhaoshuang
2023-05-11 21:20 ` [PATCH] ipruote2: " patchwork-bot+netdevbpf
6 siblings, 0 replies; 13+ messages in thread
From: zhaoshuang @ 2023-05-11 0:37 UTC (permalink / raw)
To: pawel.chmielewski; +Cc: netdev
@pawel.chmielewski
A signoff has been deleted. Pls review again
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH] iproute2: optimize code and fix some mem-leak risk
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
` (4 preceding siblings ...)
2023-05-11 0:37 ` [PATCH] ipruote2: " zhaoshuang
@ 2023-05-11 0:37 ` zhaoshuang
2023-05-11 2:34 ` Stephen Hemminger
` (2 more replies)
2023-05-11 21:20 ` [PATCH] ipruote2: " patchwork-bot+netdevbpf
6 siblings, 3 replies; 13+ messages in thread
From: zhaoshuang @ 2023-05-11 0:37 UTC (permalink / raw)
To: pawel.chmielewski; +Cc: netdev
From: zhaoshuang <zhaoshuang@uniontech.com>
Signed-off-by: zhaoshuang <izhaoshuang@163.com>
---
bridge/mdb.c | 4 ++++
devlink/devlink.c | 21 +++++++++------------
ip/ipaddrlabel.c | 1 +
ip/ipfou.c | 1 +
ip/ipila.c | 1 +
ip/ipnetconf.c | 1 +
ip/ipnexthop.c | 4 ++++
ip/iproute.c | 6 ++++++
ip/iprule.c | 1 +
ip/iptuntap.c | 1 +
ip/tunnel.c | 2 ++
tc/tc_class.c | 1 +
tc/tc_filter.c | 1 +
tc/tc_qdisc.c | 1 +
14 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/bridge/mdb.c b/bridge/mdb.c
index dcc08235..fbb4f704 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -466,12 +466,14 @@ static int mdb_show(int argc, char **argv)
/* get mdb entries */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_array(PRINT_JSON, "mdb");
if (rtnl_dump_filter(&rth, print_mdbs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_array(PRINT_JSON, NULL);
@@ -479,12 +481,14 @@ static int mdb_show(int argc, char **argv)
/* get router ports */
if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) {
perror("Cannot send dump request");
+ delete_json_obj();
return -1;
}
open_json_object("router");
if (rtnl_dump_filter(&rth, print_rtrs, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
close_json_object();
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 019ffc23..26513142 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -205,6 +205,14 @@ struct ifname_map {
char *ifname;
};
+static void ifname_map_free(struct ifname_map *ifname_map)
+{
+ free(ifname_map->ifname);
+ free(ifname_map->dev_name);
+ free(ifname_map->bus_name);
+ free(ifname_map);
+}
+
static struct ifname_map *ifname_map_alloc(const char *bus_name,
const char *dev_name,
uint32_t port_index,
@@ -221,23 +229,12 @@ static struct ifname_map *ifname_map_alloc(const char *bus_name,
ifname_map->ifname = strdup(ifname);
if (!ifname_map->bus_name || !ifname_map->dev_name ||
!ifname_map->ifname) {
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
+ ifname_map_free(ifname_map);
return NULL;
}
return ifname_map;
}
-static void ifname_map_free(struct ifname_map *ifname_map)
-{
- free(ifname_map->ifname);
- free(ifname_map->dev_name);
- free(ifname_map->bus_name);
- free(ifname_map);
-}
-
static int ifname_map_update(struct ifname_map *ifname_map, const char *ifname)
{
char *new_ifname;
diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c
index 46f68c41..b045827a 100644
--- a/ip/ipaddrlabel.c
+++ b/ip/ipaddrlabel.c
@@ -113,6 +113,7 @@ static int ipaddrlabel_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_addrlabel, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipfou.c b/ip/ipfou.c
index ed99a548..760cfee2 100644
--- a/ip/ipfou.c
+++ b/ip/ipfou.c
@@ -318,6 +318,7 @@ static int do_show(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_fou_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipila.c b/ip/ipila.c
index 335d15f6..4f6d578f 100644
--- a/ip/ipila.c
+++ b/ip/ipila.c
@@ -150,6 +150,7 @@ static int do_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&genl_rth, print_ila_mapping, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 7ddaefb4..9ae6c45e 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -209,6 +209,7 @@ dump:
*/
if (errno == EOPNOTSUPP &&
filter.family == AF_UNSPEC) {
+ delete_json_obj();
filter.family = AF_INET;
goto dump;
}
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 9f16b809..abbf4d45 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -1021,6 +1021,7 @@ static int ipnh_get_id(__u32 id)
new_json_obj(json);
if (print_nexthop_nocache(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
@@ -1106,6 +1107,7 @@ static int ipnh_list_flush(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_nocache, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1181,6 +1183,7 @@ static int ipnh_bucket_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_nexthop_bucket, stdout) < 0) {
+ delete_json_obj();
fprintf(stderr, "Dump terminated\n");
return -2;
}
@@ -1221,6 +1224,7 @@ static int ipnh_bucket_get_id(__u32 id, __u16 bucket_index)
new_json_obj(json);
if (print_nexthop_bucket(answer, (void *)stdout) < 0) {
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iproute.c b/ip/iproute.c
index a7cd9543..7909c4a2 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1977,6 +1977,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
if (rtnl_dump_filter_errhndlr(&rth, filter_fn, stdout,
save_route_errhndlr, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -2;
}
@@ -2172,18 +2173,21 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
if (answer->nlmsg_type != RTM_NEWROUTE) {
fprintf(stderr, "Not a route?\n");
+ delete_json_obj();
free(answer);
return -1;
}
len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0) {
fprintf(stderr, "Wrong len %d\n", len);
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2195,6 +2199,7 @@ static int iproute_get(int argc, char **argv)
r->rtm_src_len = 8*RTA_PAYLOAD(tb[RTA_PREFSRC]);
} else if (!tb[RTA_SRC]) {
fprintf(stderr, "Failed to connect the route\n");
+ delete_json_obj();
free(answer);
return -1;
}
@@ -2217,6 +2222,7 @@ static int iproute_get(int argc, char **argv)
if (print_route(answer, (void *)stdout) < 0) {
fprintf(stderr, "An error :-)\n");
+ delete_json_obj();
free(answer);
return -1;
}
diff --git a/ip/iprule.c b/ip/iprule.c
index 458607ef..e503e5c6 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -714,6 +714,7 @@ static int iprule_list_flush_or_save(int argc, char **argv, int action)
new_json_obj(json);
if (rtnl_dump_filter(&rth, filter_fn, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index ab7d5d87..552599e9 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -441,6 +441,7 @@ static int do_show(int argc, char **argv)
if (rtnl_dump_filter(&rth, print_tuntap, NULL) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
diff --git a/ip/tunnel.c b/ip/tunnel.c
index 75cb0b51..c5c7a31f 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -419,11 +419,13 @@ int do_tunnels_list(struct tnl_print_nlmsg_info *info)
new_json_obj(json);
if (rtnl_linkdump_req(&rth, preferred_family) < 0) {
perror("Cannot send dump request\n");
+ delete_json_obj();
return -1;
}
if (rtnl_dump_filter(&rth, print_nlmsg_tunnel, info) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return -1;
}
delete_json_obj();
diff --git a/tc/tc_class.c b/tc/tc_class.c
index 096fa2ec..65776180 100644
--- a/tc/tc_class.c
+++ b/tc/tc_class.c
@@ -453,6 +453,7 @@ static int tc_class_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_class, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_filter.c b/tc/tc_filter.c
index 700a09f6..12a21433 100644
--- a/tc/tc_filter.c
+++ b/tc/tc_filter.c
@@ -734,6 +734,7 @@ static int tc_filter_list(int cmd, int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_filter, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index 92ceb4c2..b137517b 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -433,6 +433,7 @@ static int tc_qdisc_list(int argc, char **argv)
new_json_obj(json);
if (rtnl_dump_filter(&rth, print_qdisc, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
+ delete_json_obj();
return 1;
}
delete_json_obj();
--
2.20.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] iproute2: optimize code and fix some mem-leak risk
2023-05-11 0:37 ` [PATCH] iproute2: " zhaoshuang
@ 2023-05-11 2:34 ` Stephen Hemminger
2023-05-11 15:38 ` Pawel Chmielewski
2023-05-11 21:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 13+ messages in thread
From: Stephen Hemminger @ 2023-05-11 2:34 UTC (permalink / raw)
To: zhaoshuang; +Cc: pawel.chmielewski, netdev
On Thu, 11 May 2023 08:37:26 +0800
zhaoshuang <izhaoshuang@163.com> wrote:
> From: zhaoshuang <zhaoshuang@uniontech.com>
>
> Signed-off-by: zhaoshuang <izhaoshuang@163.com>
Looks good thanks. Will wait for any other feedback
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] iproute2: optimize code and fix some mem-leak risk
2023-05-11 0:37 ` [PATCH] iproute2: " zhaoshuang
2023-05-11 2:34 ` Stephen Hemminger
@ 2023-05-11 15:38 ` Pawel Chmielewski
2023-05-11 21:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 13+ messages in thread
From: Pawel Chmielewski @ 2023-05-11 15:38 UTC (permalink / raw)
To: zhaoshuang; +Cc: netdev
On Thu, May 11, 2023 at 08:37:26AM +0800, zhaoshuang wrote:
> From: zhaoshuang <zhaoshuang@uniontech.com>
>
> Signed-off-by: zhaoshuang <izhaoshuang@163.com>
> ---
Thank you for fixing the typo
Reviewed-by: Pawel Chmielewski <pawel.chmielewski@intel.com>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] iproute2: optimize code and fix some mem-leak risk
2023-05-11 0:37 ` [PATCH] iproute2: " zhaoshuang
2023-05-11 2:34 ` Stephen Hemminger
2023-05-11 15:38 ` Pawel Chmielewski
@ 2023-05-11 21:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-05-11 21:20 UTC (permalink / raw)
To: zhaoshuang; +Cc: pawel.chmielewski, netdev
Hello:
This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:
On Thu, 11 May 2023 08:37:26 +0800 you wrote:
> From: zhaoshuang <zhaoshuang@uniontech.com>
>
> Signed-off-by: zhaoshuang <izhaoshuang@163.com>
> ---
> bridge/mdb.c | 4 ++++
> devlink/devlink.c | 21 +++++++++------------
> ip/ipaddrlabel.c | 1 +
> ip/ipfou.c | 1 +
> ip/ipila.c | 1 +
> ip/ipnetconf.c | 1 +
> ip/ipnexthop.c | 4 ++++
> ip/iproute.c | 6 ++++++
> ip/iprule.c | 1 +
> ip/iptuntap.c | 1 +
> ip/tunnel.c | 2 ++
> tc/tc_class.c | 1 +
> tc/tc_filter.c | 1 +
> tc/tc_qdisc.c | 1 +
> 14 files changed, 34 insertions(+), 12 deletions(-)
Here is the summary with links:
- iproute2: optimize code and fix some mem-leak risk
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=7e8cdfa2eac5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] ipruote2: optimize code and fix some mem-leak risk
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
` (5 preceding siblings ...)
2023-05-11 0:37 ` [PATCH] iproute2: " zhaoshuang
@ 2023-05-11 21:20 ` patchwork-bot+netdevbpf
6 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-05-11 21:20 UTC (permalink / raw)
To: zhaoshuang; +Cc: netdev
Hello:
This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:
On Wed, 10 May 2023 21:36:16 +0800 you wrote:
> From: zhaoshuang <zhaoshuang@uniontech.com>
>
> Signed-off-by: zhaoshuang <zhaoshuang@uniontech.com>
> Signed-off-by: zhaoshuang <izhaoshuang@163.com>
> ---
> bridge/mdb.c | 4 ++++
> devlink/devlink.c | 21 +++++++++------------
> ip/ipaddrlabel.c | 1 +
> ip/ipfou.c | 1 +
> ip/ipila.c | 1 +
> ip/ipnetconf.c | 1 +
> ip/ipnexthop.c | 4 ++++
> ip/iproute.c | 6 ++++++
> ip/iprule.c | 1 +
> ip/iptuntap.c | 1 +
> ip/tunnel.c | 2 ++
> tc/tc_class.c | 1 +
> tc/tc_filter.c | 1 +
> tc/tc_qdisc.c | 1 +
> 14 files changed, 34 insertions(+), 12 deletions(-)
Here is the summary with links:
- ipruote2: optimize code and fix some mem-leak risk
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=7e8cdfa2eac5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-05-11 21:20 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-10 13:36 [PATCH] ipruote2: optimize code and fix some mem-leak risk zhaoshuang
2023-05-10 13:55 ` Pawel Chmielewski
2023-05-10 13:59 ` Pawel Chmielewski
2023-05-10 15:24 ` [PATCH] iproute2: " zhaoshuang
2023-05-10 15:47 ` [PATCH] ipruote2: " zhaoshuang
2023-05-10 15:47 ` [PATCH] iproute2: " zhaoshuang
2023-05-10 20:39 ` Stephen Hemminger
2023-05-11 0:37 ` [PATCH] ipruote2: " zhaoshuang
2023-05-11 0:37 ` [PATCH] iproute2: " zhaoshuang
2023-05-11 2:34 ` Stephen Hemminger
2023-05-11 15:38 ` Pawel Chmielewski
2023-05-11 21:20 ` patchwork-bot+netdevbpf
2023-05-11 21:20 ` [PATCH] ipruote2: " 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).