From patchwork Wed Apr 14 22:47:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Chu X-Patchwork-Id: 92506 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3EMlp3x000736 for ; Wed, 14 Apr 2010 22:47:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755332Ab0DNWrv (ORCPT ); Wed, 14 Apr 2010 18:47:51 -0400 Received: from nspiron-3.llnl.gov ([128.115.41.83]:37821 "EHLO smtp.llnl.gov" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755166Ab0DNWru (ORCPT ); Wed, 14 Apr 2010 18:47:50 -0400 X-Attachments: 0001-fix-libibnetdisc-cache-error-path-memleak.patch Received: from auk31.llnl.gov (HELO [134.9.93.159]) ([134.9.93.159]) by smtp.llnl.gov with ESMTP; 14 Apr 2010 15:47:50 -0700 Subject: [infiniband-diags] [1/2] fix libibnetdisc cache error path memleak From: Al Chu To: Sasha Khapyorsky Cc: "linux-rdma@vger.kernel.org" Date: Wed, 14 Apr 2010 15:47:49 -0700 Message-Id: <1271285269.17987.139.camel@auk31.llnl.gov> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-19.el5) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 14 Apr 2010 22:47:52 +0000 (UTC) diff --git a/infiniband-diags/libibnetdisc/src/ibnetdisc.c b/infiniband-diags/libibnetdisc/src/ibnetdisc.c index c895de9..dfd7dce 100644 --- a/infiniband-diags/libibnetdisc/src/ibnetdisc.c +++ b/infiniband-diags/libibnetdisc/src/ibnetdisc.c @@ -510,7 +510,7 @@ error: return NULL; } -static void destroy_node(ibnd_node_t * node) +void destroy_node(ibnd_node_t * node) { int p = 0; diff --git a/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c b/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c index 480a0a2..2ec353d 100644 --- a/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c +++ b/infiniband-diags/libibnetdisc/src/ibnetdisc_cache.c @@ -113,6 +113,7 @@ typedef struct ibnd_node_cache { ibnd_port_cache_key_t *port_cache_keys; struct ibnd_node_cache *next; struct ibnd_node_cache *htnext; + int node_stored_to_fabric; } ibnd_node_cache_t; typedef struct ibnd_port_cache { @@ -122,6 +123,7 @@ typedef struct ibnd_port_cache { ibnd_port_cache_key_t remoteport_cache_key; struct ibnd_port_cache *next; struct ibnd_port_cache *htnext; + int port_stored_to_fabric; } ibnd_port_cache_t; typedef struct ibnd_fabric_cache { @@ -257,6 +259,9 @@ static int _load_header_info(int fd, ibnd_fabric_cache_t * fabric_cache, static void _destroy_ibnd_node_cache(ibnd_node_cache_t * node_cache) { free(node_cache->port_cache_keys); + if (!node_cache->node_stored_to_fabric + && node_cache->node) + destroy_node(node_cache->node); free(node_cache); } @@ -283,6 +288,9 @@ static void _destroy_ibnd_fabric_cache(ibnd_fabric_cache_t * fabric_cache) while (port_cache) { port_cache_next = port_cache->next; + if (!port_cache->port_stored_to_fabric + && port_cache->port) + free(port_cache->port); free(port_cache); port_cache = port_cache_next; @@ -387,8 +395,6 @@ static int _load_node(int fd, ibnd_fabric_cache_t * fabric_cache) return 0; cleanup: - /* note, no need to destroy node through destroy_node(), nothing else malloced */ - free(node); _destroy_ibnd_node_cache(node_cache); return -1; } @@ -500,6 +506,7 @@ static int _fill_port(ibnd_fabric_cache_t * fabric_cache, ibnd_node_t * node, } node->ports[port_cache->port->portnum] = port_cache->port; + port_cache->port_stored_to_fabric++; /* achu: needed if user wishes to re-cache a loaded fabric. * Otherwise, mostly unnecessary to do this. @@ -532,6 +539,8 @@ static int _rebuild_nodes(ibnd_fabric_cache_t * fabric_cache) add_to_type_list(node_cache->node, fabric_cache->fabric); + node_cache->node_stored_to_fabric++; + /* Rebuild node ports array */ if (!(node->ports = diff --git a/infiniband-diags/libibnetdisc/src/internal.h b/infiniband-diags/libibnetdisc/src/internal.h index 57034f9..32d567e 100644 --- a/infiniband-diags/libibnetdisc/src/internal.h +++ b/infiniband-diags/libibnetdisc/src/internal.h @@ -98,4 +98,6 @@ void add_to_portguid_hash(ibnd_port_t * port, ibnd_port_t * hash[]); void add_to_type_list(ibnd_node_t * node, ibnd_fabric_t * fabric); +void destroy_node(ibnd_node_t * node); + #endif /* _INTERNAL_H_ */