]> 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:47:17 +0000 (16:47 +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 94e83c2a86fed4dd7be068070d4e0c1b95cfaefe..3febcb193be3345edfb9de1d02a955e476a3bec5 100644 (file)
--- a/src/cdp.c
+++ b/src/cdp.c
@@ -462,8 +462,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 be422f606a2e7ec50bc5f61f96fa21136610c58d..dd545a2d1eca31632162be7decfe913abd3e7939 100644 (file)
--- a/src/edp.c
+++ b/src/edp.c
@@ -476,8 +476,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 91016d600c3c71ccacd94899102dfaed3bc59554..22ff68f906bef046238e6094f922e248930f7850 100644 (file)
@@ -786,7 +786,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 5f3b7dece62faaaddf9e6c43acc11975ef858db0..b2347c225cf6c4306be375b78c55cc5eebd1403c 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 84ad3f525254293ed0e2ded34c745dcbddf50f36..302b9273ac4d8fb6b8e0814a16a8bdeed89e6bf8 100644 (file)
@@ -333,7 +333,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 ff0e2729faa1ee7fabc71e9fc306d713e1291c06..e55b8fda3fa060b1ef0f5322cc66d7289a0177cf 100644 (file)
@@ -375,8 +375,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;
 }