From patchwork Mon Mar 7 10:03:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Netes X-Patchwork-Id: 615711 X-Patchwork-Delegate: alexne@voltaire.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p27EEBf7011626 for ; Mon, 7 Mar 2011 14:15:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753485Ab1CGOPo (ORCPT ); Mon, 7 Mar 2011 09:15:44 -0500 Received: from mail.mellanox.co.il ([194.90.237.43]:45010 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751413Ab1CGOPo (ORCPT ); Mon, 7 Mar 2011 09:15:44 -0500 Received: from Internal Mail-Server by MTLPINE2 (envelope-from alexne@mellanox.com) with SMTP; 7 Mar 2011 12:04:01 +0200 Received: from MTRCASDAG01.mtl.com (172.25.0.174) by MTLCAS01.mtl.com (10.0.8.71) with Microsoft SMTP Server (TLS) id 14.1.270.1; Mon, 7 Mar 2011 12:04:01 +0200 Received: from localhost (172.25.6.157) by MTRCASDAG01.mtl.com (172.25.0.174) with Microsoft SMTP Server (TLS) id 14.1.270.1; Mon, 7 Mar 2011 12:03:59 +0200 Date: Mon, 7 Mar 2011 12:03:59 +0200 From: Alex Netes To: Subject: [PATCH] opensm: fixed potential memory leak in osm_ucast_ftree() Message-ID: <20110307100359.GK5577@calypso.voltaire.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [172.25.6.157] 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.6 (demeter1.kernel.org [140.211.167.41]); Mon, 07 Mar 2011 14:15:45 +0000 (UTC) diff --git a/opensm/osm_ucast_ftree.c b/opensm/osm_ucast_ftree.c index 11980cc..51e252a 100644 --- a/opensm/osm_ucast_ftree.c +++ b/opensm/osm_ucast_ftree.c @@ -554,25 +554,40 @@ static ftree_sw_t *sw_create(IN ftree_fabric_t * p_ftree, p_sw->down_port_groups = (ftree_port_group_t **) malloc(ports_num * sizeof(ftree_port_group_t *)); + if (p_sw->down_port_groups == NULL) + goto FREE_P_SW; + p_sw->up_port_groups = (ftree_port_group_t **) malloc(ports_num * sizeof(ftree_port_group_t *)); + if (p_sw->sibling_port_groups == NULL) + goto FREE_DOWN; + p_sw->sibling_port_groups = (ftree_port_group_t **) malloc(ports_num * sizeof(ftree_port_group_t *)); - - if (!p_sw->down_port_groups || !p_sw->up_port_groups - || !p_sw->sibling_port_groups) - return NULL; + if (p_sw->sibling_port_groups == NULL) + goto FREE_UP; /* initialize lft buffer */ memset(p_osm_sw->new_lft, OSM_NO_PATH, p_osm_sw->lft_size); p_sw->hops = malloc((p_osm_sw->max_lid_ho + 1) * sizeof(*(p_sw->hops))); if (p_sw->hops == NULL) - return NULL; + goto FREE_SIBLING; + memset(p_sw->hops, OSM_NO_PATH, p_osm_sw->max_lid_ho + 1); return p_sw; + +FREE_SIBLING: + free(p_sw->sibling_port_groups); +FREE_UP: + free(p_sw->up_port_groups); +FREE_DOWN: + free(p_sw->down_port_groups); +FREE_P_SW: + free(p_sw); + return NULL; } /* sw_create() */ /***************************************************/ @@ -1662,6 +1677,7 @@ static int fabric_create_leaf_switch_array(IN ftree_fabric_t * p_ftree) if (!p_ftree->leaf_switches) { osm_log(&p_ftree->p_osm->log, OSM_LOG_SYS, "Fat-tree routing: Memory allocation failed\n"); + free(all_switches_at_leaf_level); res = -1; goto Exit; }