From dbfa89c6e597011144032f1bcde300cfe2c64e47 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 31 Aug 2014 21:56:49 +0200 Subject: [PATCH] lldpd: handle early cleanup in case interface cannot be created When an interface is about to be created but an external condition makes it impossible, the cleanup may crash because the interface was incomplete. Check things exist before cleanup. --- src/daemon/event.c | 5 ++++- src/daemon/lldpd.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/daemon/event.c b/src/daemon/event.c index 14a3855a..2379d2b4 100644 --- a/src/daemon/event.c +++ b/src/daemon/event.c @@ -570,7 +570,10 @@ void levent_hardware_release(struct lldpd_hardware *hardware) { struct lldpd_events *ev, *ev_next; - event_free(hardware->h_timer); hardware->h_timer = NULL; + if (hardware->h_timer) { + event_free(hardware->h_timer); + hardware->h_timer = NULL; + } if (!hardware->h_recv) return; log_debug("event", "release events for %s", hardware->h_ifname); diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 4848f6f3..d4d83189 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -208,7 +208,7 @@ lldpd_hardware_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware) log_debug("alloc", "cleanup hardware port %s", hardware->h_ifname); lldpd_port_cleanup(&hardware->h_lport, 1); - if (hardware->h_ops->cleanup) + if (hardware->h_ops && hardware->h_ops->cleanup) hardware->h_ops->cleanup(cfg, hardware); levent_hardware_release(hardware); free(hardware); -- 2.39.5