From patchwork Thu Jan 7 02:35:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 564156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 26551140082 for ; Thu, 7 Jan 2016 13:37:45 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=yvmUyEXt; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 452BE10A35; Wed, 6 Jan 2016 18:37:44 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 5122D10A33 for ; Wed, 6 Jan 2016 18:37:43 -0800 (PST) Received: from bar4.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 75EE216225E for ; Wed, 6 Jan 2016 19:37:42 -0700 (MST) X-ASG-Debug-ID: 1452134261-03dc2108f766cd40001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar4.cudamail.com with ESMTP id 916vXhxBGyDBCbQV (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 06 Jan 2016 19:37:41 -0700 (MST) X-Barracuda-Envelope-From: u9012063@gmail.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO mail-pa0-f51.google.com) (209.85.220.51) by mx3-pf1.cudamail.com with ESMTPS (RC4-SHA encrypted); 7 Jan 2016 02:36:41 -0000 Received-SPF: pass (mx3-pf1.cudamail.com: SPF record at _netblocks.google.com designates 209.85.220.51 as permitted sender) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.51 Received: by mail-pa0-f51.google.com with SMTP id cy9so246205460pac.0 for ; Wed, 06 Jan 2016 18:36:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=fK2Hgz/tUNlaA3nY7Jm1cIpfAdFm8p0T+OCV4L7ymrg=; b=yvmUyEXt82c+W2wC+thNUihxfdrYvQbm8lm0Q3/PnqUdv3cuFIdnGbsaTezlhbps3d O9qOsJnU/6DehYvW8qA1hY74R346mlzxnFfeO7+tBDMR+BgqmdNoQSgOlvm0t8iRibNG SoCJ8dz2yDozvbuvKYFab2q4lkr8SlY/yyKuSAj5qDstolblyb8EKa88p0sjTnW78o1B xGwL3By2QUqodN7EQdYRjReUeHW+8O9Madx0PrnaIz9n+TjdPp7wUeijUZfF1WJ+wa5E eL6SpiN3eC3Qzsr15uJ2sjHwfjknGJa3CPTHv9shuWuuqPITmGNpvUWjRqK6//CUt2D3 IvEw== X-Received: by 10.66.155.197 with SMTP id vy5mr146778859pab.109.1452134201121; Wed, 06 Jan 2016 18:36:41 -0800 (PST) Received: from vm-dev.localdomain ([208.91.2.4]) by smtp.gmail.com with ESMTPSA id tv6sm91025907pab.4.2016.01.06.18.36.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Jan 2016 18:36:40 -0800 (PST) X-CudaMail-Envelope-Sender: u9012063@gmail.com X-Barracuda-Apparent-Source-IP: 208.91.2.4 From: William Tu To: dev@openvswitch.org X-CudaMail-MID: CM-V1-105062903 X-CudaMail-DTE: 010616 X-CudaMail-Originating-IP: 209.85.220.51 Date: Wed, 6 Jan 2016 18:35:23 -0800 X-ASG-Orig-Subj: [##CM-V1-105062903##][PATCH] test-aa: fix memory leak reported by valgrind Message-Id: <1452134123-14579-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.5.0 X-GBUdb-Analysis: 0, 209.85.220.51, Ugly c=0.389962 p=-0.318182 Source Normal X-MessageSniffer-Rules: 0-0-0-8761-c X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1452134261 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, DKIM_SIGNED, MAILTO_TO_SPAM_ADDR, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.25905 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.00 MAILTO_TO_SPAM_ADDR URI: Includes a link to a likely spammer email 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Subject: [ovs-dev] [PATCH] test-aa: fix memory leak reported by valgrind X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" 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 --- lib/ovs-lldp.c | 34 ++++++++++++++++++++++++++++++---- lib/ovs-lldp.h | 1 + tests/test-aa.c | 5 +++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lib/ovs-lldp.c b/lib/ovs-lldp.c index bd1729c..16225b5 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 e780e5b..71dff44 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 */ diff --git a/tests/test-aa.c b/tests/test-aa.c index 2da572d..eedefeb 100644 --- a/tests/test-aa.c +++ b/tests/test-aa.c @@ -267,6 +267,11 @@ test_aa_send(void) /* Verify auto attach values */ check_received_aa(&hardware.h_lport, nport, map_init); + lldpd_chassis_cleanup(nchassis, true); + lldpd_port_cleanup(nport, true); + free(nport); + lldp_destroy_dummy(lldp); + return 0; }