bgpd: reduce struct attr_extra allocations/freeing
Try to use on stack structs for temporary uses.
Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index b63ac4c..2d82acc 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -319,10 +319,14 @@
void
bgp_attr_dup (struct attr *new, struct attr *orig)
{
+ struct attr_extra *extra = new->extra;
+
*new = *orig;
if (orig->extra)
{
- new->extra = bgp_attr_extra_new();
+ /* if caller provided attr_extra space use it */
+ if (! extra)
+ new->extra = bgp_attr_extra_new();
*new->extra = *orig->extra;
}
}