]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
When cleaning up a port in the context of refreshing gathered
authorVincent Bernat <bernat@luffy.cx>
Sun, 8 Mar 2009 15:47:17 +0000 (16:47 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sun, 8 Mar 2009 15:50:32 +0000 (16:50 +0100)
information, don't clean LLDP-MED location information. However, when
cleaning up a port for removal, clean them.

This fixes a regression introduced when fixing a memory leak. The
regression was introduced in:
 63f4b177e9b98ee2531e24a584fb7eaa754d0a14

src/cdp.c
src/edp.c
src/lldp.c
src/lldpd.c
src/lldpd.h
src/sonmp.c

index 3581e39852efae9c0cb7b476d73d48ffe7aff953..33302cca4ae6569262b2c1b76b90b54772b3ecbe 100644 (file)
--- a/src/cdp.c
+++ b/src/cdp.c
@@ -492,8 +492,7 @@ cdp_decode(struct lldpd *cfg, char *frame, int s,
 
 malformed:
        lldpd_chassis_cleanup(chassis);
-       lldpd_port_cleanup(port);
-       free(port);
+       lldpd_port_cleanup(port, 1);
        return -1;
 }
 
index 0e2e525742a3033e91021a911322940cab31e0b7..7fa7ef2e682056672d608e3dbb833b5edbc7f084 100644 (file)
--- a/src/edp.c
+++ b/src/edp.c
@@ -481,8 +481,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s,
 
 malformed:
        lldpd_chassis_cleanup(chassis);
-       lldpd_port_cleanup(port);
-       free(port);
+       lldpd_port_cleanup(port, 1);
        return -1;
 }
 
index 172d9b4c75da43398a10afff2ebcf1091e456fa3..9f10b61fd88c8a02e83e667994679993854a330c 100644 (file)
@@ -972,7 +972,6 @@ lldp_decode(struct lldpd *cfg, char *frame, int s,
        return 1;
 malformed:
        lldpd_chassis_cleanup(chassis);
-       lldpd_port_cleanup(port);
-       free(port);
+       lldpd_port_cleanup(port, 1);
        return -1;
 }
index 4ef4526399479279bb64504df17beba2cdca5bfc..1697d335923ed0ab54ed25546efc926e2f1f9dd2 100644 (file)
@@ -365,21 +365,25 @@ lldpd_vlan_cleanup(struct lldpd_port *port)
 }
 #endif
 
+/* If `all' is true, clear all information, including information that
+   are not refreshed periodically. If `all' is true, also free the
+   port. */
 void
-lldpd_port_cleanup(struct lldpd_port *port)
+lldpd_port_cleanup(struct lldpd_port *port, int all)
 {
 #ifdef ENABLE_LLDPMED
        int i;
-       for (i=0; i < LLDPMED_LOCFORMAT_LAST; i++)
-               free(port->p_med_location[i].data);
+       if (all)
+               for (i=0; i < LLDPMED_LOCFORMAT_LAST; i++)
+                       free(port->p_med_location[i].data);
 #endif
 #ifdef ENABLE_DOT1
        lldpd_vlan_cleanup(port);
 #endif
        free(port->p_id);
        free(port->p_descr);
-       /* Don't free port, we may use this function on statically
-          allocated ports */
+       if (all)
+               free(port);
 }
 
 void
@@ -404,8 +408,7 @@ void
 lldpd_remote_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware, int reset)
 {
        if (hardware->h_rport != NULL) {
-               lldpd_port_cleanup(hardware->h_rport);
-               free(hardware->h_rport);
+               lldpd_port_cleanup(hardware->h_rport, 1);
                hardware->h_rport = NULL;
        }
        if (hardware->h_rchassis != NULL) {
@@ -426,7 +429,7 @@ lldpd_remote_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware, int res
 void
 lldpd_hardware_cleanup(struct lldpd_hardware *hardware)
 {
-       lldpd_port_cleanup(&hardware->h_lport);
+       lldpd_port_cleanup(&hardware->h_lport, 1);
        free(hardware->h_proto_macs);
        free(hardware->h_llastframe);
        free(hardware);
@@ -557,7 +560,7 @@ lldpd_port_add(struct lldpd *cfg, struct ifaddrs *ifa)
 #ifdef ENABLE_DOT1
                TAILQ_INIT(&hardware->h_lport.p_vlans);
        } else {
-               lldpd_port_cleanup(&hardware->h_lport);
+               lldpd_port_cleanup(&hardware->h_lport, 0);
 #endif
        }
 
@@ -975,8 +978,7 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s,
 
 cleanup:
        lldpd_chassis_cleanup(chassis);
-       lldpd_port_cleanup(port);
-       free(port);
+       lldpd_port_cleanup(port, 1);
        return;
 }
 
index 203da1352ac496718dfd034eeff861b2fc081202..0eb63a01d92a120d1794cf36639766a0393748bc 100644 (file)
@@ -334,7 +334,7 @@ void         lldpd_hardware_cleanup(struct lldpd_hardware *);
 void    lldpd_vlan_cleanup(struct lldpd_port *);
 #endif
 void    lldpd_remote_cleanup(struct lldpd *, struct lldpd_hardware *, int);
-void    lldpd_port_cleanup(struct lldpd_port *);
+void    lldpd_port_cleanup(struct lldpd_port *, int);
 void    lldpd_chassis_cleanup(struct lldpd_chassis *);
 
 /* lldp.c */
index ed8ba737bcd9b230d33a5ad0ac4203caecc053b1..8b51b76f792ef5134abcb38eb6fa57ce643e10ee 100644 (file)
@@ -330,8 +330,7 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s,
 
 malformed:
        lldpd_chassis_cleanup(chassis);
-       lldpd_port_cleanup(port);
-       free(port);
+       lldpd_port_cleanup(port, 1);
        return -1;
 }