summaryrefslogtreecommitdiff
path: root/bgpd/bgp_attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_attr.c')
-rw-r--r--bgpd/bgp_attr.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 2cbd7bc3..1dce39bc 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -321,11 +321,24 @@ bgp_attr_dup (struct attr *new, struct attr *orig)
struct attr_extra *extra = new->extra;
*new = *orig;
- if (orig->extra)
+ /* if caller provided attr_extra space, use it in any case.
+ *
+ * This is neccesary even if orig->extra equals NULL, because otherwise
+ * memory may be later allocated on the heap by bgp_attr_extra_get.
+ *
+ * That memory would eventually be leaked, because the caller must not
+ * call bgp_attr_extra_free if he provided attr_extra on the stack.
+ */
+ if (extra)
+ {
+ new->extra = extra;
+ memset(new->extra, 0, sizeof(struct attr_extra));
+ if (orig->extra)
+ *new->extra = *orig->extra;
+ }
+ else if (orig->extra)
{
- /* if caller provided attr_extra space use it */
- if (! extra)
- new->extra = bgp_attr_extra_new();
+ new->extra = bgp_attr_extra_new();
*new->extra = *orig->extra;
}
}