From d243d47d63622172109e43a50238dc597a6c0ce8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 27 Feb 2009 13:46:02 +0100 Subject: [PATCH] Fix a memory leak that can happen when a port is removed or renamed --- src/cdp.c | 1 + src/edp.c | 1 + src/lldp.c | 1 + src/lldpd.c | 6 +++++- src/sonmp.c | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cdp.c b/src/cdp.c index 55c66224..3581e398 100644 --- a/src/cdp.c +++ b/src/cdp.c @@ -493,6 +493,7 @@ cdp_decode(struct lldpd *cfg, char *frame, int s, malformed: lldpd_chassis_cleanup(chassis); lldpd_port_cleanup(port); + free(port); return -1; } diff --git a/src/edp.c b/src/edp.c index 64184555..0e2e5257 100644 --- a/src/edp.c +++ b/src/edp.c @@ -482,6 +482,7 @@ edp_decode(struct lldpd *cfg, char *frame, int s, malformed: lldpd_chassis_cleanup(chassis); lldpd_port_cleanup(port); + free(port); return -1; } diff --git a/src/lldp.c b/src/lldp.c index 004ddda4..172d9b4c 100644 --- a/src/lldp.c +++ b/src/lldp.c @@ -973,5 +973,6 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, malformed: lldpd_chassis_cleanup(chassis); lldpd_port_cleanup(port); + free(port); return -1; } diff --git a/src/lldpd.c b/src/lldpd.c index d1d996d9..e6d16e4d 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -378,7 +378,8 @@ lldpd_port_cleanup(struct lldpd_port *port) #endif free(port->p_id); free(port->p_descr); - free(port); + /* Don't free port, we may use this function on statically + allocated ports */ } void @@ -404,6 +405,7 @@ lldpd_remote_cleanup(struct lldpd *cfg, struct lldpd_hardware *hardware, int res { if (hardware->h_rport != NULL) { lldpd_port_cleanup(hardware->h_rport); + free(hardware->h_rport); hardware->h_rport = NULL; } if (hardware->h_rchassis != NULL) { @@ -427,6 +429,7 @@ lldpd_hardware_cleanup(struct lldpd_hardware *hardware) #ifdef ENABLE_DOT1 lldpd_vlan_cleanup(&hardware->h_lport); #endif + lldpd_port_cleanup(&hardware->h_lport); free(hardware->h_proto_macs); free(hardware->h_llastframe); free(hardware); @@ -976,6 +979,7 @@ lldpd_decode(struct lldpd *cfg, char *frame, int s, cleanup: lldpd_chassis_cleanup(chassis); lldpd_port_cleanup(port); + free(port); return; } diff --git a/src/sonmp.c b/src/sonmp.c index cccce679..ed8ba737 100644 --- a/src/sonmp.c +++ b/src/sonmp.c @@ -331,6 +331,7 @@ sonmp_decode(struct lldpd *cfg, char *frame, int s, malformed: lldpd_chassis_cleanup(chassis); lldpd_port_cleanup(port); + free(port); return -1; } -- 2.39.5