diff options
author | Thomas Huth <thuth@redhat.com> | 2016-01-15 18:36:35 +0100 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-01-18 11:58:12 +1100 |
commit | c0fbf94bc5d667957df0eeffbfc001829179b332 (patch) | |
tree | 556e8766c249a1ba3e31e313aa4f913c066682c4 /clients | |
parent | c74ddc995439881edf1ec582591e5e50ff8e7ca5 (diff) | |
download | SLOF-c0fbf94bc5d667957df0eeffbfc001829179b332.zip SLOF-c0fbf94bc5d667957df0eeffbfc001829179b332.tar.gz SLOF-c0fbf94bc5d667957df0eeffbfc001829179b332.tar.bz2 |
net-snk: Fix memory leak in ip6_to_multicast_mac() / send_ipv6()
ip6_to_multicast_mac() uses a malloc to allocate a 6 bytes buffer
for the MAC address - which never gets freed again! That means
we're leaking memory for every multicast IPv6 packet that gets
send out. Fix it by simply using the "uint8_t mac[6]" array from
send_ipv6() instead.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'clients')
-rw-r--r-- | clients/net-snk/app/netlib/ipv6.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/clients/net-snk/app/netlib/ipv6.c b/clients/net-snk/app/netlib/ipv6.c index 5b38ee0..3579dc9 100644 --- a/clients/net-snk/app/netlib/ipv6.c +++ b/clients/net-snk/app/netlib/ipv6.c @@ -419,17 +419,12 @@ ip6_is_multicast (ip6_addr_t * ip) * (e.g. UDP or ICMPv6) * * @param *ip - pointer to IPv6 address + * @param *mc_mac pointer to an array with 6 bytes (for the MAC address) * @return pointer to Multicast MAC address */ static uint8_t * -ip6_to_multicast_mac (ip6_addr_t * ip) +ip6_to_multicast_mac (ip6_addr_t * ip, uint8_t *mc_mac) { - uint8_t *mc_mac; - - mc_mac = malloc(ETH_ALEN); - if (!mc_mac) - return NULL; - mc_mac[0] = 0x33; mc_mac[1] = 0x33; memcpy (mc_mac+2, (uint8_t *) &(ip->addr)+12, 4); @@ -532,7 +527,7 @@ send_ipv6 (int fd, void* buffer, int len) // If address is a multicast address, create a proper mac address if (ip6_is_multicast (&ip_dst)) { - mac_addr = ip6_to_multicast_mac (&ip_dst); + mac_addr = ip6_to_multicast_mac (&ip_dst, mac); } else { // Check if the MAC address is already cached |