* [iproute PATCH v2 1/5] ipvrf: Fix error path of vrf_switch()
2017-08-17 17:09 [iproute PATCH v2 0/5] Covscan: Fix potential memory leaks Phil Sutter
@ 2017-08-17 17:09 ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 2/5] ifstat: Fix memleak in error case Phil Sutter
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2017-08-17 17:09 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Apart from trying to close(-1), this also leaked memory.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
ip/ipvrf.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
index 0094cf8557cd7..e6fad32abd956 100644
--- a/ip/ipvrf.c
+++ b/ip/ipvrf.c
@@ -372,12 +372,12 @@ static int vrf_switch(const char *name)
/* -1 on length to add '/' to the end */
if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0)
- return -1;
+ goto out;
if (vrf_path(vpath, sizeof(vpath)) < 0) {
fprintf(stderr, "Failed to get base cgroup path: %s\n",
strerror(errno));
- return -1;
+ goto out;
}
/* if path already ends in netns then don't add it again */
@@ -428,13 +428,14 @@ static int vrf_switch(const char *name)
snprintf(pid, sizeof(pid), "%d", getpid());
if (write(fd, pid, strlen(pid)) < 0) {
fprintf(stderr, "Failed to join cgroup\n");
- goto out;
+ goto out2;
}
rc = 0;
+out2:
+ close(fd);
out:
free(mnt);
- close(fd);
return rc;
}
--
2.13.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [iproute PATCH v2 2/5] ifstat: Fix memleak in error case
2017-08-17 17:09 [iproute PATCH v2 0/5] Covscan: Fix potential memory leaks Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 1/5] ipvrf: Fix error path of vrf_switch() Phil Sutter
@ 2017-08-17 17:09 ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 3/5] ifstat: Fix memleak in dump_kern_db() for json output Phil Sutter
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2017-08-17 17:09 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/ifstat.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/misc/ifstat.c b/misc/ifstat.c
index a853ee6d7e3b3..8fa354265a9a1 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -143,8 +143,10 @@ static int get_nlmsg_extended(const struct sockaddr_nl *who,
struct rtattr *attr;
attr = parse_rtattr_one_nested(sub_type, tb[filter_type]);
- if (attr == NULL)
+ if (attr == NULL) {
+ free(n);
return 0;
+ }
memcpy(&n->val, RTA_DATA(attr), sizeof(n->val));
}
memset(&n->rate, 0, sizeof(n->rate));
--
2.13.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [iproute PATCH v2 3/5] ifstat: Fix memleak in dump_kern_db() for json output
2017-08-17 17:09 [iproute PATCH v2 0/5] Covscan: Fix potential memory leaks Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 1/5] ipvrf: Fix error path of vrf_switch() Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 2/5] ifstat: Fix memleak in error case Phil Sutter
@ 2017-08-17 17:09 ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 4/5] ss: Fix potential memleak in unix_stats_print() Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 5/5] tipc/bearer: Fix resource leak in error path Phil Sutter
4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2017-08-17 17:09 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Looks like this was forgotten when converting to common json output
formatter.
Fixes: fcc16c2287bf8 ("provide common json output formatter")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/ifstat.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/misc/ifstat.c b/misc/ifstat.c
index 8fa354265a9a1..1be21703bf14c 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -535,8 +535,12 @@ static void dump_kern_db(FILE *fp)
else
print_one_if(fp, n, n->val);
}
- if (json_output)
- fprintf(fp, "\n} }\n");
+ if (jw) {
+ jsonw_end_object(jw);
+
+ jsonw_end_object(jw);
+ jsonw_destroy(&jw);
+ }
}
static void dump_incr_db(FILE *fp)
--
2.13.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [iproute PATCH v2 4/5] ss: Fix potential memleak in unix_stats_print()
2017-08-17 17:09 [iproute PATCH v2 0/5] Covscan: Fix potential memory leaks Phil Sutter
` (2 preceding siblings ...)
2017-08-17 17:09 ` [iproute PATCH v2 3/5] ifstat: Fix memleak in dump_kern_db() for json output Phil Sutter
@ 2017-08-17 17:09 ` Phil Sutter
2017-08-17 17:09 ` [iproute PATCH v2 5/5] tipc/bearer: Fix resource leak in error path Phil Sutter
4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2017-08-17 17:09 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Fixes: 2d0e538f3e1cd ("ss: Drop list traversal from unix_stats_print()")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
misc/ss.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/misc/ss.c b/misc/ss.c
index 07eecfa7a36db..34c6da5443642 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -3169,8 +3169,10 @@ static int unix_show(struct filter *f)
if (name[0]) {
u->name = strdup(name);
- if (!u->name)
+ if (!u->name) {
+ free(u);
break;
+ }
}
if (u->rport) {
--
2.13.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [iproute PATCH v2 5/5] tipc/bearer: Fix resource leak in error path
2017-08-17 17:09 [iproute PATCH v2 0/5] Covscan: Fix potential memory leaks Phil Sutter
` (3 preceding siblings ...)
2017-08-17 17:09 ` [iproute PATCH v2 4/5] ss: Fix potential memleak in unix_stats_print() Phil Sutter
@ 2017-08-17 17:09 ` Phil Sutter
4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2017-08-17 17:09 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
tipc/bearer.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tipc/bearer.c b/tipc/bearer.c
index 810344f672af1..c3d4491f8f6ef 100644
--- a/tipc/bearer.c
+++ b/tipc/bearer.c
@@ -163,6 +163,7 @@ static int nl_add_udp_enable_opts(struct nlmsghdr *nlh, struct opt *opts,
if (!remip) {
if (generate_multicast(loc->ai_family, buf, sizeof(buf))) {
fprintf(stderr, "Failed to generate multicast address\n");
+ freeaddrinfo(loc);
return -EINVAL;
}
remip = buf;
@@ -177,6 +178,8 @@ static int nl_add_udp_enable_opts(struct nlmsghdr *nlh, struct opt *opts,
if (rem->ai_family != loc->ai_family) {
fprintf(stderr, "UDP local and remote AF mismatch\n");
+ freeaddrinfo(rem);
+ freeaddrinfo(loc);
return -EINVAL;
}
--
2.13.1
^ permalink raw reply related [flat|nested] 6+ messages in thread