]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
event: avoid socket leak if we cannot register netlink socket
authorVincent Bernat <bernat@luffy.cx>
Mon, 31 Dec 2012 17:56:02 +0000 (18:56 +0100)
committerVincent Bernat <bernat@luffy.cx>
Mon, 31 Dec 2012 17:56:02 +0000 (18:56 +0100)
src/daemon/event.c
src/daemon/interfaces-linux.c
src/daemon/lldpd.h

index b39f4a3ecac9311c334e0d21808549c9c082916a..89163e2e83d8f7b40bafc98c6855db07579467f7 100644 (file)
@@ -633,7 +633,7 @@ levent_iface_recv(evutil_socket_t fd, short what, void *arg)
        }
 }
 
-void
+int
 levent_iface_subscribe(struct lldpd *cfg, int socket)
 {
        log_debug("event", "subscribe to interface changes from socket %d",
@@ -644,15 +644,16 @@ levent_iface_subscribe(struct lldpd *cfg, int socket)
        if (cfg->g_iface_event == NULL) {
                log_warnx("event",
                    "unable to allocate a new event for interface changes");
-               return;
+               return -1;
        }
        if (event_add(cfg->g_iface_event, NULL) == -1) {
                log_warnx("event",
                    "unable to schedule new interface changes event");
                event_free(cfg->g_iface_event);
                cfg->g_iface_event = NULL;
-               return;
+               return -1;
        }
+       return 0;
 }
 
 static void
index b0294d4538312180bc4cada896b444cc40e49a31..3a0bc30d93a701ff8f889ec421cf104338ddeb33 100644 (file)
@@ -856,7 +856,8 @@ interfaces_update(struct lldpd *cfg)
                        log_warnx("interfaces", "unable to subscribe to netlink notifications");
                        goto end;
                }
-               levent_iface_subscribe(cfg, s);
+               if (levent_iface_subscribe(cfg, s) == -1)
+                       close(s);
        }
 
 end:
index 7935ea0eb0eb0dd83e23293d5ecf392179dd232a..26e361a552272b96fad835b6d443190bd1bb997c 100644 (file)
@@ -139,7 +139,7 @@ void         levent_hardware_add_fd(struct lldpd_hardware *, int);
 void    levent_hardware_release(struct lldpd_hardware *);
 void    levent_ctl_notify(char *, int, struct lldpd_port *);
 void    levent_send_now(struct lldpd *);
-void    levent_iface_subscribe(struct lldpd *, int);
+int     levent_iface_subscribe(struct lldpd *, int);
 void    levent_schedule_pdu(struct lldpd_hardware *);
 
 /* lldp.c */