From fb85b1d1a760729b59fd6a866886ea1d5ccc1b34 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Fri, 5 Oct 2018 03:53:14 +0200 Subject: [PATCH] netdev: Check that netdev->device is not NULL Check that netdev->device is not NULL before doing device_remove() (which would crash) and emitting NETDEV_WATCH_EVENT_DEL. It may be NULL if the initial RTM_SETLINK has failed to bring device UP. --- src/netdev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/netdev.c b/src/netdev.c index 9e1bf1bd..a46d689d 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -612,9 +612,11 @@ static void netdev_free(void *data) netdev->set_powered_cmd_id = 0; } - WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t, - netdev, NETDEV_WATCH_EVENT_DEL); - device_remove(netdev->device); + if (netdev->device) { + WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t, + netdev, NETDEV_WATCH_EVENT_DEL); + device_remove(netdev->device); + } watchlist_destroy(&netdev->frame_watches); watchlist_destroy(&netdev->station_watches);