diff options
author | Tom Gundersen <teg@jklm.no> | 2015-09-24 01:22:05 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-10-11 15:04:16 +0200 |
commit | 054f0db48775d566e4f55feb7cda0f721a9eb485 (patch) | |
tree | 9ca1fdb3320ff1690c1e72ff0965ab64f175bcfc /src/network/networkd-address.c | |
parent | cf1d700da3fe04cd4c27980a292301694be3b05f (diff) |
networkd: manager - avoid unnecessary memory allocation
Don't allocate Address objects only to free them again when processing
rtnl events.
Diffstat (limited to 'src/network/networkd-address.c')
-rw-r--r-- | src/network/networkd-address.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 9600b957fe..0414ced48a 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -198,11 +198,21 @@ bool address_equal(Address *a1, Address *a2) { return address_compare_func(a1, a2) == 0; } -int address_add(Link *link, Address *address) { +int address_add(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) { + _cleanup_address_free_ Address *address = NULL; int r; assert(link); - assert(address); + assert(in_addr); + assert(ret); + + r = address_new(&address); + if (r < 0) + return r; + + address->family = family; + address->in_addr = *in_addr; + address->prefixlen = prefixlen; r = set_ensure_allocated(&link->addresses, &address_hash_ops); if (r < 0) @@ -214,6 +224,9 @@ int address_add(Link *link, Address *address) { address->link = link; + *ret = address; + address = NULL; + return 0; } |