From patchwork Mon Aug 27 06:42:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10576413 X-Patchwork-Delegate: hal@mellanox.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94B28174A for ; Mon, 27 Aug 2018 06:43:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 883612971F for ; Mon, 27 Aug 2018 06:43:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C98829721; Mon, 27 Aug 2018 06:43:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10B552971F for ; Mon, 27 Aug 2018 06:43:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727100AbeH0K2U (ORCPT ); Mon, 27 Aug 2018 06:28:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55832 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726874AbeH0K2U (ORCPT ); Mon, 27 Aug 2018 06:28:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17DCC40216E9; Mon, 27 Aug 2018 06:43:03 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75D772166B41; Mon, 27 Aug 2018 06:43:01 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [PATCH 5/5] osm_ucast_nue.c: fix resource leak in nue_create_context Date: Mon, 27 Aug 2018 14:42:33 +0800 Message-Id: <20180827064233.3218-5-honli@redhat.com> In-Reply-To: <20180827064233.3218-4-honli@redhat.com> References: <20180827064233.3218-1-honli@redhat.com> <20180827064233.3218-2-honli@redhat.com> <20180827064233.3218-3-honli@redhat.com> <20180827064233.3218-4-honli@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 27 Aug 2018 06:43:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 27 Aug 2018 06:43:03 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'honli@redhat.com' RCPT:'' Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Honggang Li Issue was found by Coverity. Error: RESOURCE_LEAK (CWE-772): opensm-3.3.20/opensm/osm_ucast_nue.c:3159: alloc_fn: Storage is returned from allocation function "malloc". opensm-3.3.20/opensm/osm_ucast_nue.c:3159: var_assign: Assigning: "nue_ctx" = storage returned from "malloc(336UL)". opensm-3.3.20/opensm/osm_ucast_nue.c:3164: noescape: Resource "nue_ctx" is not freed or pointed-to in "create_context". opensm-3.3.20/opensm/osm_ucast_nue.c:3109:43: noescape: "create_context(nue_context_t *)" does not free or save its parameter "nue_ctx". opensm-3.3.20/opensm/osm_ucast_nue.c:3166: leaked_storage: Variable "nue_ctx" going out of scope leaks the storage it points to. |# 3164| err = create_context(nue_ctx); |# 3165| if (err) |# 3166|-> return NULL; |# 3167| } else { |# 3168| OSM_LOG(osm->sm.ucast_mgr.p_log, OSM_LOG_ERROR, Signed-off-by: Honggang Li --- opensm/osm_ucast_nue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opensm/osm_ucast_nue.c b/opensm/osm_ucast_nue.c index 13684738..0ef84ebc 100644 --- a/opensm/osm_ucast_nue.c +++ b/opensm/osm_ucast_nue.c @@ -3162,8 +3162,10 @@ static nue_context_t *nue_create_context(const osm_opensm_t * osm, nue_ctx->routing_type = routing_type; nue_ctx->mgr = (osm_ucast_mgr_t *) & (osm->sm.ucast_mgr); err = create_context(nue_ctx); - if (err) + if (err) { + free(nue_ctx); return NULL; + } } else { OSM_LOG(osm->sm.ucast_mgr.p_log, OSM_LOG_ERROR, "ERR NUE01: cannot allocate memory for nue_ctx\n");