]> git.puffer.fish Git - matthieu/frr.git/commitdiff
*: fix coverity warnings - resource leaks
authorRenato Westphal <renato@opensourcerouting.org>
Sun, 22 Oct 2017 23:14:21 +0000 (21:14 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Tue, 24 Oct 2017 21:30:30 +0000 (19:30 -0200)
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 <renato@opensourcerouting.org>
bgpd/bgp_mpath.c
lib/hash.c
ripngd/ripngd.c
tools/start-stop-daemon.c
vtysh/vtysh.c
zebra/rtadv.c

index d3ee140bb412a0946dc7614498cac03c4c52d6bf..9d32c4bee11d916937162ef007df83be9b957c49 100644 (file)
@@ -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;
index f222279216a6f590fa6aeccd789d523cddcbac3c..4894b65affedf705d1eb6de797408c8378c5a326 100644 (file)
@@ -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;
        }
index daa2526a0cde695ad11c0f7f5e553d43cd0979e4..673f0637c79cfc83fa0c3dd96a74ce8f4e8053d6 100644 (file)
@@ -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. */
index 30dc6484ae181a96b07054394a71cd40e9d763d7..8dc16f420922be9ebca533e846393a1720350423 100644 (file)
@@ -538,10 +538,7 @@ static void parse_options(int argc, char *const *argv)
                        execname = optarg;
                        break;
                case 'c': /* --chuid <username>|<uid> */
-                       /* 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 */
index 061c25cea5f5a74cb1c7b7a40bac80590d4a864c..92c6f64e1c4d2faed2ac9b7aab6aa361ea564cdc 100644 (file)
@@ -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++)
index 7f9bc473156582ba04bf965dd4ca2deb035b0e04..a1e1602bf833b6b4fbe9ded39500d0cb86279dec 100644 (file)
@@ -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;
        }