neigh: Fix nl_addr leak in handle_encoded_mac on prefix mismatch handle_encoded_mac() builds an nl_addr prefix object via nl_addr_build() for each encoded_prefixes[] entry whose address family matches the destination. The reference obtained from nl_addr_build() was only released through nl_addr_put() on the matching path. When the family matched but the address prefix did not, the loop took the continue branch, which left the allocated nl_addr unreleased and leaked one reference per non-matching entry. Move the nl_addr_put() call so the prefix is released on both the mismatch (continue) and match paths, and drop the now-unnecessary "prefix = NULL" from the for-statement update expression since each iteration that allocates a prefix now releases it before the next allocation. This leak is reachable whenever a destination address family matches an encoded_prefixes[] entry but the prefix comparison fails, e.g. a non-multicast, non-link-local IPv6 address triggering the AF_INET6 entries to be tried and skipped. Signed-off-by: wangwanxia <wangwanxia@kingsoft.com>
diff --git a/libibverbs/neigh.c b/libibverbs/neigh.c index 7eed95f..58bb489 100644 --- a/libibverbs/neigh.c +++ b/libibverbs/neigh.c
@@ -474,7 +474,7 @@ for (i = 0; i < sizeof(encoded_prefixes)/sizeof(encoded_prefixes[0]) && - ret; prefix = NULL, i++) { + ret; i++) { if (encoded_prefixes[i].family != family) continue; @@ -492,8 +492,10 @@ if (nl_addr_cmp_prefix_msb(nl_addr_get_binary_addr(dst), nl_addr_get_prefixlen(dst), nl_addr_get_binary_addr(prefix), - nl_addr_get_prefixlen(prefix))) + nl_addr_get_prefixlen(prefix))) { + nl_addr_put(prefix); continue; + } ret = encoded_prefixes[i].getter(dst, ll_addr); nl_addr_put(prefix);