From 8900367cd26c148200b4788cd9ae05995ceeb74c Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 1 Jul 2014 19:41:45 +0200 Subject: networkd: netdev - take ref when creating netdevs We were doing this correctly for when the callback takes the Link object, but must also do it for the cases it takes the NetDev object. --- src/network/networkd-netdev.c | 8 +++++--- src/network/networkd-veth.c | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/network') diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index a53f046540..20917e334b 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -224,7 +224,7 @@ static int netdev_enter_ready(NetDev *netdev) { /* callback for netdev's created without a backing Link */ static int netdev_create_handler(sd_rtnl *rtnl, sd_rtnl_message *m, void *userdata) { - NetDev *netdev = userdata; + _cleanup_netdev_unref_ NetDev *netdev = userdata; int r; assert(netdev->state != _NETDEV_STATE_INVALID); @@ -388,9 +388,11 @@ static int netdev_create(NetDev *netdev, Link *link, sd_rtnl_message_handler_t c if (link) r = sd_rtnl_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL); - else + else { r = sd_rtnl_call_async(netdev->manager->rtnl, req, &netdev_create_handler, netdev, 0, NULL); - if (r < 0) { + + netdev_ref(netdev); + } if (r < 0) { log_error_netdev(netdev, "Could not send rtnetlink message: %s", strerror(-r)); return r; diff --git a/src/network/networkd-veth.c b/src/network/networkd-veth.c index 3584981cbc..3eac90ba90 100644 --- a/src/network/networkd-veth.c +++ b/src/network/networkd-veth.c @@ -145,6 +145,8 @@ int netdev_create_veth(NetDev *netdev, sd_rtnl_message_handler_t callback) { return r; } + netdev_ref(netdev); + log_debug_netdev(netdev, "Creating veth netdev: %s", netdev_kind_to_string(netdev->kind)); -- cgit v1.2.3-54-g00ecf