From patchwork Tue Sep 7 15:12:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yevgeny Kliteynik X-Patchwork-Id: 161211 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 o87FD3XP002121 for ; Tue, 7 Sep 2010 15:13:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757285Ab0IGPNB (ORCPT ); Tue, 7 Sep 2010 11:13:01 -0400 Received: from mail.mellanox.co.il ([194.90.237.43]:58401 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757129Ab0IGPNB (ORCPT ); Tue, 7 Sep 2010 11:13:01 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from kliteyn@mellanox.co.il) with SMTP; 7 Sep 2010 18:12:20 +0300 Received: from [10.4.1.29] (10.4.1.29) by mtlmail01.mtl.com (10.0.8.12) with Microsoft SMTP Server id 8.2.254.0; Tue, 7 Sep 2010 18:12:58 +0300 Message-ID: <4C86567A.5060400@mellanox.co.il> Date: Tue, 7 Sep 2010 18:12:58 +0300 From: Yevgeny Kliteynik Reply-To: kliteyn@dev.mellanox.co.il User-Agent: Thunderbird 1.5.0.5 (X11/20060719) MIME-Version: 1.0 To: Sasha Khapyorsky , Linux RDMA Subject: [PATCH] opensm/osm_console.c: fix memory and file descriptor leaks 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 (demeter1.kernel.org [140.211.167.41]); Tue, 07 Sep 2010 15:13:03 +0000 (UTC) diff --git a/opensm/opensm/osm_console.c b/opensm/opensm/osm_console.c index bc7bea3..29a6c83 100644 --- a/opensm/opensm/osm_console.c +++ b/opensm/opensm/osm_console.c @@ -1302,12 +1302,13 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out) /* Check we have at least one expression to match */ if (p_head_regexp == NULL) { fprintf(out, "No valid expression provided. Aborting\n"); + goto Exit; return; } if (p_osm->sm.p_subn->need_update != 0) { fprintf(out, "Subnet is not ready yet. Try again later\n"); - return; + goto Free_and_exit; } /* Subnet doesn't need to be updated so we can carry on */ @@ -1333,14 +1334,16 @@ static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out) } CL_PLOCK_RELEASE(p_osm->sm.p_lock); - if (output != out) - fclose(output); +Free_and_exit: for (; p_head_regexp; p_head_regexp = p_regexp) { p_regexp = p_head_regexp->next; regfree(&p_head_regexp->exp); free(p_head_regexp); } +Exit: + if (output != out) + fclose(output); } static void help_dump_portguid(FILE * out, int detail)