diff options
author | William Tu <u9012063@gmail.com> | 2016-01-06 18:35:23 -0800 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2016-01-11 09:02:03 -0800 |
commit | 9547cc66f5ee35209da988717556dcaf1fb28a23 (patch) | |
tree | 6c577a7747b6d68214b76898b1034848e13cd38c /lib | |
parent | cf2bc30c6ad5f3dfe9c5f55550fffb20efde6b06 (diff) | |
download | openvswitch-9547cc66f5ee35209da988717556dcaf1fb28a23.tar.gz |
test-aa: Fix memory leak reported by valgrind.
test case 1698: auto-attach - packet tests
Report several leaks at lldp_create_dummy(), the patch fixes the
following 3 leaks:
{lldp_send (lldp.c:334), lldp_decode (lldp.c:374),
lldp_create_dummy (ovs-lldp.c:890)}
test_aa_send (test-aa.c:252)
test_aa_main (test-aa.c:281)
Comments:
1. Create a new function "lldp_destroy_dummy()" because
many structures and its elements, ex: lldp_hardware and lldp_chassis,
are from stack not heap (see test_aa_send). As a result, calling
lldpd_cleanup() is incorrect.
2. Remove lchassis->c_id = xmalloc(ETH_ADDR_LEN);
because it is overwritten at test_aa_send()
3. remove memcpy(&hw->h_lport.p_element.system_id.system_mac,
lchassis->c_id, lchassis->c_id_len);
because the source buf is empty
Signed-off-by: William Tu <u9012063@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ovs-lldp.c | 34 | ||||
-rw-r--r-- | lib/ovs-lldp.h | 1 |
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c index bd1729c72..16225b511 100644 --- a/lib/ovs-lldp.c +++ b/lib/ovs-lldp.c @@ -887,7 +887,6 @@ lldp_create_dummy(void) lchassis->c_cap_enabled = LLDP_CAP_BRIDGE; lchassis->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; lchassis->c_id_len = ETH_ADDR_LEN; - lchassis->c_id = xmalloc(ETH_ADDR_LEN); list_init(&lchassis->c_mgmt); lchassis->c_ttl = LLDP_CHASSIS_TTL; @@ -911,8 +910,6 @@ lldp_create_dummy(void) /* Auto Attach element tlv */ hw->h_lport.p_element.type = LLDP_TLV_AA_ELEM_TYPE_CLIENT_VIRTUAL_SWITCH; hw->h_lport.p_element.mgmt_vlan = 0; - memcpy(&hw->h_lport.p_element.system_id.system_mac, - lchassis->c_id, lchassis->c_id_len); hw->h_lport.p_element.system_id.conn_type = LLDP_TLV_AA_ELEM_CONN_TYPE_SINGLE; hw->h_lport.p_element.system_id.rsvd = 0; @@ -950,7 +947,7 @@ lldp_unref(struct lldp *lldp) free(lldp); } -/* Unreference a specific LLDP instance. +/* Reference a specific LLDP instance. */ struct lldp * lldp_ref(const struct lldp *lldp_) @@ -961,3 +958,32 @@ lldp_ref(const struct lldp *lldp_) } return lldp; } + +void +lldp_destroy_dummy(struct lldp *lldp) +{ + struct lldpd_hardware *hw, *hw_next; + struct lldpd_chassis *chassis, *chassis_next; + struct lldpd *cfg; + + if (!lldp) { + return; + } + + cfg = lldp->lldpd; + + LIST_FOR_EACH_SAFE (hw, hw_next, h_entries, &cfg->g_hardware) { + list_remove(&hw->h_entries); + free(hw->h_lport.p_lastframe); + free(hw); + } + + LIST_FOR_EACH_SAFE (chassis, chassis_next, list, &cfg->g_chassis) { + list_remove(&chassis->list); + free(chassis); + } + + free(lldp->lldpd); + free(lldp); +} + diff --git a/lib/ovs-lldp.h b/lib/ovs-lldp.h index e780e5b56..71dff4491 100644 --- a/lib/ovs-lldp.h +++ b/lib/ovs-lldp.h @@ -103,5 +103,6 @@ int aa_mapping_unregister(void *aux); /* Used by unit tests */ struct lldp * lldp_create_dummy(void); +void lldp_destroy_dummy(struct lldp *); #endif /* OVS_LLDP_H */ |