From patchwork Thu Feb 21 17:06:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hal Rosenstock X-Patchwork-Id: 2172201 X-Patchwork-Delegate: hal@mellanox.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 1539FDF215 for ; Thu, 21 Feb 2013 17:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754400Ab3BURG7 (ORCPT ); Thu, 21 Feb 2013 12:06:59 -0500 Received: from mail-bk0-f41.google.com ([209.85.214.41]:43521 "EHLO mail-bk0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753746Ab3BURG6 (ORCPT ); Thu, 21 Feb 2013 12:06:58 -0500 Received: by mail-bk0-f41.google.com with SMTP id q16so4225354bkw.14 for ; Thu, 21 Feb 2013 09:06:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:content-type:content-transfer-encoding:x-gm-message-state; bh=wjjrEfPaAOFM0hbxHTv8t6BXZWdTngeUAZek+ikC4p0=; b=bl3Q0SZhaq/TvZYaoqDTsnNIu4d3e0QNoTVktq7np5idAT9jZtZKuHmsH/x8J6xs/L ilxE5gdF8zQCl5Sq10Jc9fn0JYrCpgHhn5YSVcuisidJxD0vMxx+B367VOJQHHyuINp+ gF+TTV2Y5qkZ6hJgCyPK33bnN9LIjFdjiH9PWJUKablNmrPCMjZvxtpjye+Nyls+HAjd 96VCexEI3KzY2A571sXLFS/ukpNFYf5kZVMN6ZU36hZneN0V7pXuRyfmctRDKzanzTwG I7pb97B60Mal1qT/jiXqh8vJ1QZTMA5dJHATRwPyU8zrp8BMZszZUHGj6gmqzkKov0c8 o+pw== X-Received: by 10.205.129.16 with SMTP id hg16mr10999099bkc.11.1361466416613; Thu, 21 Feb 2013 09:06:56 -0800 (PST) Received: from [192.168.1.102] (c-71-234-225-85.hsd1.ct.comcast.net. [71.234.225.85]) by mx.google.com with ESMTPS id r17sm24720084bkw.21.2013.02.21.09.06.54 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 21 Feb 2013 09:06:55 -0800 (PST) Message-ID: <5126542D.8000007@dev.mellanox.co.il> Date: Thu, 21 Feb 2013 12:06:53 -0500 From: Hal Rosenstock User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: "linux-rdma (linux-rdma@vger.kernel.org)" CC: Alex Netes Subject: [PATCH] libibumad: Fix memory leak in resolve_ca_port X-Gm-Message-State: ALoCoQkmKJ7oH6SGmbuNMlrZ9kYdXgCmPoBlpKerJ6A9w5FeKW2yL67/7jHaS8arx4OggP9Rx2d9 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Signed-off-by: Alex Netes --- -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/umad.c b/src/umad.c index 45a9423..8f817d2 100644 --- a/src/umad.c +++ b/src/umad.c @@ -234,7 +234,7 @@ static int resolve_ca_port(char *ca_name, int *port) { umad_ca_t ca; int active = -1, up = -1; - int i; + int i, ret = 0; TRACE("checking ca '%s'", ca_name); @@ -243,19 +243,27 @@ static int resolve_ca_port(char *ca_name, int *port) if (ca.node_type == 2) { *port = 0; /* switch sma port 0 */ - return 1; + ret = 1; + goto Exit; } if (*port > 0) { /* check only the port the user wants */ - if (*port > ca.numports) - return -1; - if (!ca.ports[*port]) - return -1; - if (ca.ports[*port]->state == 4) - return 1; + if (*port > ca.numports) { + ret = -1; + goto Exit; + } + if (!ca.ports[*port]) { + ret = -1; + goto Exit; + } + if (ca.ports[*port]->state == 4) { + ret = 1; + goto Exit; + } if (ca.ports[*port]->phys_state != 3) - return 0; - return -1; + goto Exit; + ret = -1; + goto Exit; } for (i = 0; i <= ca.numports; i++) { @@ -283,13 +291,18 @@ static int resolve_ca_port(char *ca_name, int *port) } } + if (active >= 0) { + ret = 1; + goto Exit; + } + if (up >= 0) { + ret = 0; + goto Exit; + } + ret = -1; +Exit: release_ca(&ca); - - if (active >= 0) - return 1; - if (up >= 0) - return 0; - return -1; + return ret; } static char *resolve_ca_name(char *ca_name, int *best_port)