From: Renato Westphal Date: Sun, 22 Oct 2017 23:14:21 +0000 (-0200) Subject: *: fix coverity warnings - resource leaks X-Git-Tag: frr-4.0-dev~191^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=44f12f209f7019c0abbec0f919cb18a136cd7bee;p=mirror%2Ffrr.git *: fix coverity warnings - resource leaks These are mostly trivial fixes for leaks in the error path of some functions. The changes in bgpd/bgp_mpath.c deserves a bit of explanation though. In the bgp_info_mpath_aggregate_update() function, we were allocating memory for the lcomm variable but doing nothing with it. Since the code for communities, extended communities and large communities is pretty much the same in this function, it's clear that this was a copy and paste error where most of the ext. community code was copied but not all of it as it should have been. Signed-off-by: Renato Westphal --- diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index d3ee140bb4..9d32c4bee1 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -751,6 +751,10 @@ void bgp_info_mpath_aggregate_update(struct bgp_info *new_best, attr.ecommunity = ecomm; attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); } + if (lcomm) { + attr.lcommunity = lcomm; + attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); + } /* Zap multipath attr nexthop so we set nexthop to self */ attr.nexthop.s_addr = 0; diff --git a/lib/hash.c b/lib/hash.c index f222279216..4894b65aff 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -395,6 +395,7 @@ DEFUN_NOSH(show_hash_stats, pthread_mutex_lock(&_hashes_mtx); if (!_hashes) { pthread_mutex_unlock(&_hashes_mtx); + ttable_del(tt); vty_out(vty, "No hash tables in use.\n"); return CMD_SUCCESS; } diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index daa2526a0c..673f0637c7 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -101,21 +101,21 @@ static int ripng_make_socket(void) setsockopt_so_recvbuf(sock, 8096); ret = setsockopt_ipv6_pktinfo(sock, 1); if (ret < 0) - return ret; + goto error; #ifdef IPTOS_PREC_INTERNETCONTROL ret = setsockopt_ipv6_tclass(sock, IPTOS_PREC_INTERNETCONTROL); if (ret < 0) - return ret; + goto error; #endif ret = setsockopt_ipv6_multicast_hops(sock, 255); if (ret < 0) - return ret; + goto error; ret = setsockopt_ipv6_multicast_loop(sock, 0); if (ret < 0) - return ret; + goto error; ret = setsockopt_ipv6_hoplimit(sock, 1); if (ret < 0) - return ret; + goto error; memset(&ripaddr, 0, sizeof(ripaddr)); ripaddr.sin6_family = AF_INET6; @@ -132,11 +132,15 @@ static int ripng_make_socket(void) zlog_err("Can't bind ripng socket: %s.", safe_strerror(errno)); if (ripngd_privs.change(ZPRIVS_LOWER)) zlog_err("ripng_make_socket: could not lower privs"); - return ret; + goto error; } if (ripngd_privs.change(ZPRIVS_LOWER)) zlog_err("ripng_make_socket: could not lower privs"); return sock; + +error: + close(sock); + return ret; } /* Send RIPng packet. */ diff --git a/tools/start-stop-daemon.c b/tools/start-stop-daemon.c index 30dc6484ae..8dc16f4209 100644 --- a/tools/start-stop-daemon.c +++ b/tools/start-stop-daemon.c @@ -538,10 +538,7 @@ static void parse_options(int argc, char *const *argv) execname = optarg; break; case 'c': /* --chuid | */ - /* we copy the string just in case we need the - * argument later. */ - changeuser = strdup(optarg); - changeuser = strtok(changeuser, ":"); + changeuser = strtok(optarg, ":"); changegroup = strtok(NULL, ":"); break; case 'r': /* --chroot /new/root */ diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 061c25cea5..92c6f64e1c 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -573,6 +573,7 @@ int vtysh_mark_file(const char *filename) * appropriate */ if (strlen(vty_buf_trimmed) == 3 && strncmp("end", vty_buf_trimmed, 3) == 0) { + cmd_free_strvec(vline); continue; } @@ -804,8 +805,6 @@ static int vtysh_rl_describe(void) } else if (rl_end && isspace((int)rl_line_buffer[rl_end - 1])) vector_set(vline, NULL); - describe = cmd_describe_command(vline, vty, &ret); - fprintf(stdout, "\n"); /* Ambiguous and no match error. */ @@ -824,6 +823,8 @@ static int vtysh_rl_describe(void) break; } + describe = cmd_describe_command(vline, vty, &ret); + /* Get width of command string. */ width = 0; for (i = 0; i < vector_active(describe); i++) diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 7f9bc47315..a1e1602bf8 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -675,6 +675,7 @@ static int rtadv_make_socket(void) sizeof(struct icmp6_filter)); if (ret < 0) { zlog_info("ICMP6_FILTER set fail: %s", safe_strerror(errno)); + close(sock); return ret; }