From c1c69e43cda64122b599746df4d1c6c5d8b52e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 22 May 2015 13:40:57 +0300 Subject: lib: allow caller to provide prefix storage in sockunion2hostprefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoids a dynamic allocation which is usually freed immediate afterwards. Signed-off-by: Timo Teräs Signed-off-by: David Lamparter --- bgpd/bgp_network.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'bgpd') diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index cea430cc..97650964 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -304,28 +304,27 @@ static int bgp_update_address (struct interface *ifp, const union sockunion *dst, union sockunion *addr) { - struct prefix *p, *sel, *d; + struct prefix *p, *sel, d; struct connected *connected; struct listnode *node; int common; - d = sockunion2hostprefix (dst); + sockunion2hostprefix (dst, &d); sel = NULL; common = -1; for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) { p = connected->address; - if (p->family != d->family) + if (p->family != d.family) continue; - if (prefix_common_bits (p, d) > common) + if (prefix_common_bits (p, &d) > common) { sel = p; - common = prefix_common_bits (sel, d); + common = prefix_common_bits (sel, &d); } } - prefix_free (d); if (!sel) return 1; -- cgit v1.2.3