From a0edeaf8c46a54c032633cd529c617f92db28685 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 8 Mar 2009 16:47:17 +0100 Subject: [PATCH] When cleaning up a port in the context of refreshing gathered 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 | 3 +-- src/edp.c | 3 +-- src/lldp.c | 3 +-- src/lldpd.c | 24 +++++++++++++----------- src/lldpd.h | 2 +- src/sonmp.c | 3 +-- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/cdp.c b/src/cdp.c index 94e83c2a..3febcb19 100644 --- 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; } diff --git a/src/edp.c b/src/edp.c index be422f60..dd545a2d 100644 --- 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; } diff --git a/src/lldp.c b/src/lldp.c index 91016d60..22ff68f9 100644 --- a/src/lldp.c +++ b/src/lldp.c @@ -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; } diff --git a/src/lldpd.c b/src/lldpd.c index 5f3b7dec..b2347c22 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -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; } diff --git a/src/lldpd.h b/src/lldpd.h index 84ad3f52..302b9273 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -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 */ diff --git a/src/sonmp.c b/src/sonmp.c index ff0e2729..e55b8fda 100644 --- a/src/sonmp.c +++ b/src/sonmp.c @@ -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; } -- 2.39.5