From patchwork Tue Aug 28 01:48:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10577743 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 696111390 for ; Tue, 28 Aug 2018 01:48:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AD99299F1 for ; Tue, 28 Aug 2018 01:48:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E3CB29A20; Tue, 28 Aug 2018 01:48:59 +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 E71A1299F1 for ; Tue, 28 Aug 2018 01:48:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725832AbeH1FiL (ORCPT ); Tue, 28 Aug 2018 01:38:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59800 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725724AbeH1FiL (ORCPT ); Tue, 28 Aug 2018 01:38:11 -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 3CE814023ECC; Tue, 28 Aug 2018 01:48:57 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C3B02166B41; Tue, 28 Aug 2018 01:48:55 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [PATCH 1/5] osmt_service.c: fix resource leak in osmt_get_all_services_and_check_names Date: Tue, 28 Aug 2018 09:48:30 +0800 Message-Id: <20180828014834.3046-1-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.7]); Tue, 28 Aug 2018 01:48:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 28 Aug 2018 01:48:57 +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): [#def12] opensm-3.3.20/osmtest/osmt_service.c:988: alloc_fn: Storage is returned from allocation function "malloc". opensm-3.3.20/osmtest/osmt_service.c:988: var_assign: Assigning: "p_checked_names" = storage returned from "malloc(1UL * num_of_valid_names)". opensm-3.3.20/osmtest/osmt_service.c:1091: leaked_storage: Variable "p_checked_names" going out of scope leaks the storage it points to. |# 1089| |# 1090| OSM_LOG_EXIT(&p_osmt->log); |# 1091|-> return status; |# 1092| } |# 1093| #endif Signed-off-by: Honggang Li --- osmtest/osmt_service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/osmtest/osmt_service.c b/osmtest/osmt_service.c index 5ca2ecaa..eeda1ac9 100644 --- a/osmtest/osmt_service.c +++ b/osmtest/osmt_service.c @@ -1087,6 +1087,7 @@ Exit: context.result.p_result_madw = NULL; } + free(p_checked_names); OSM_LOG_EXIT(&p_osmt->log); return status; } From patchwork Tue Aug 28 01:48:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10577745 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 64B6F1390 for ; Tue, 28 Aug 2018 01:49:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55A9F29A22 for ; Tue, 28 Aug 2018 01:49:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4997D29A20; Tue, 28 Aug 2018 01:49:01 +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 0A9CE299F1 for ; Tue, 28 Aug 2018 01:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbeH1FiO (ORCPT ); Tue, 28 Aug 2018 01:38:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47116 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725724AbeH1FiN (ORCPT ); Tue, 28 Aug 2018 01:38:13 -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 6D1A440006EC; Tue, 28 Aug 2018 01:48:59 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF88A2166B41; Tue, 28 Aug 2018 01:48:57 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [PATCH 2/5] osmtest.c: osmtest_create_inventory_file close fh before exit Date: Tue, 28 Aug 2018 09:48:31 +0800 Message-Id: <20180828014834.3046-2-honli@redhat.com> In-Reply-To: <20180828014834.3046-1-honli@redhat.com> References: <20180828014834.3046-1-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.6]); Tue, 28 Aug 2018 01:48:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 28 Aug 2018 01:48:59 +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 Signed-off-by: Honggang Li --- osmtest/osmtest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c index 4ef78eb0..b7197bf3 100644 --- a/osmtest/osmtest.c +++ b/osmtest/osmtest.c @@ -2736,9 +2736,8 @@ osmtest_create_inventory_file(IN osmtest_t * const p_osmt) if (status != IB_SUCCESS) goto Exit; - fclose(fh); - Exit: + fclose(fh); OSM_LOG_EXIT(&p_osmt->log); return (status); } From patchwork Tue Aug 28 01:48:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10577747 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 C0CC31390 for ; Tue, 28 Aug 2018 01:49:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2F5C299F1 for ; Tue, 28 Aug 2018 01:49:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A737A29A20; Tue, 28 Aug 2018 01:49:03 +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 4AA1A299F1 for ; Tue, 28 Aug 2018 01:49:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbeH1FiQ (ORCPT ); Tue, 28 Aug 2018 01:38:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39778 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725724AbeH1FiQ (ORCPT ); Tue, 28 Aug 2018 01:38:16 -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 9D6768011309; Tue, 28 Aug 2018 01:49:01 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CA492166B41; Tue, 28 Aug 2018 01:48:59 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [PATCH 3/5] osmtest.c: osmtest_parse_node delete p_node in error path Date: Tue, 28 Aug 2018 09:48:32 +0800 Message-Id: <20180828014834.3046-3-honli@redhat.com> In-Reply-To: <20180828014834.3046-2-honli@redhat.com> References: <20180828014834.3046-1-honli@redhat.com> <20180828014834.3046-2-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.8]); Tue, 28 Aug 2018 01:49:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 28 Aug 2018 01:49:01 +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): [#def14] opensm-3.3.20/osmtest/osmtest.c:6364: alloc_fn: Storage is returned from allocation function "node_new". opensm-3.3.20/osmtest/include/osmtest_subnet.h:116:2: alloc_fn: Storage is returned from allocation function "malloc". opensm-3.3.20/osmtest/include/osmtest_subnet.h:116:2: var_assign: Assigning: "p_obj" = "malloc(288UL)". opensm-3.3.20/osmtest/include/osmtest_subnet.h:118:3: noescape: Resource "p_obj" is not freed or pointed-to in function "memset". [Note: The source code implementation of the function has been overridden by a builtin model.] opensm-3.3.20/osmtest/include/osmtest_subnet.h:119:2: return_alloc: Returning allocated memory "p_obj". opensm-3.3.20/osmtest/osmtest.c:6364: var_assign: Assigning: "p_node" = storage returned from "node_new()". opensm-3.3.20/osmtest/osmtest.c:6572: leaked_storage: Variable "p_node" going out of scope leaks the storage it points to. |# 6570| Exit: |# 6571| OSM_LOG_EXIT(&p_osmt->log); |# 6572|-> return (status); |# 6573| } |# 6574| =========== Signed-off-by: Honggang Li --- osmtest/osmtest.c | 1 + 1 file changed, 1 insertion(+) diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c index b7197bf3..812563c1 100644 --- a/osmtest/osmtest.c +++ b/osmtest/osmtest.c @@ -6374,6 +6374,7 @@ osmtest_parse_node(IN osmtest_t * const p_osmt, OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0119: " "Unexpected end of file\n"); status = IB_ERROR; + node_delete(p_node); goto Exit; } From patchwork Tue Aug 28 01:48: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: 10577749 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 019F21390 for ; Tue, 28 Aug 2018 01:49:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E734F299F1 for ; Tue, 28 Aug 2018 01:49:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB8FC29A20; Tue, 28 Aug 2018 01:49: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 84C58299F1 for ; Tue, 28 Aug 2018 01:49:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726610AbeH1FiS (ORCPT ); Tue, 28 Aug 2018 01:38:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40284 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725724AbeH1FiS (ORCPT ); Tue, 28 Aug 2018 01:38:18 -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 D323220E19; Tue, 28 Aug 2018 01:49:03 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F6E82166B41; Tue, 28 Aug 2018 01:49:01 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [PATCH 4/5] osmtest.c: osmtest_parse_port fix resource leak in error path Date: Tue, 28 Aug 2018 09:48:33 +0800 Message-Id: <20180828014834.3046-4-honli@redhat.com> In-Reply-To: <20180828014834.3046-3-honli@redhat.com> References: <20180828014834.3046-1-honli@redhat.com> <20180828014834.3046-2-honli@redhat.com> <20180828014834.3046-3-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.2]); Tue, 28 Aug 2018 01:49:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 28 Aug 2018 01:49: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): [#def12] opensm-3.3.20/osmtest/osmtest.c:6588: alloc_fn: Storage is returned from allocation function "port_new". opensm-3.3.20/osmtest/include/osmtest_subnet.h:173:2: alloc_fn: Storage is returned from allocation function "malloc". opensm-3.3.20/osmtest/include/osmtest_subnet.h:173:2: var_assign: Assigning: "p_obj" = "malloc(216UL)". opensm-3.3.20/osmtest/include/osmtest_subnet.h:175:3: noescape: Resource "p_obj" is not freed or pointed-to in function "memset". [Note: The source code implementation of the function has been overridden by a builtin model.] opensm-3.3.20/osmtest/include/osmtest_subnet.h:176:2: return_alloc: Returning allocated memory "p_obj". opensm-3.3.20/osmtest/osmtest.c:6588: var_assign: Assigning: "p_port" = storage returned from "port_new()". opensm-3.3.20/osmtest/osmtest.c:6977: leaked_storage: Variable "p_port" going out of scope leaks the storage it points to. |# 6975| Exit: |# 6976| OSM_LOG_EXIT(&p_osmt->log); |# 6977|-> return (status); |# 6978| } |# 6979| Signed-off-by: Honggang Li --- osmtest/osmtest.c | 1 + 1 file changed, 1 insertion(+) diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c index 812563c1..e6f91a81 100644 --- a/osmtest/osmtest.c +++ b/osmtest/osmtest.c @@ -6599,6 +6599,7 @@ osmtest_parse_port(IN osmtest_t * const p_osmt, OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0123: " "Unexpected end of file\n"); status = IB_ERROR; + port_delete(p_port); goto Exit; } From patchwork Tue Aug 28 01:48:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honggang LI X-Patchwork-Id: 10577751 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 3A72E139B for ; Tue, 28 Aug 2018 01:49:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BBE1299F1 for ; Tue, 28 Aug 2018 01:49:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2020F29A20; Tue, 28 Aug 2018 01:49:08 +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 B603E299F1 for ; Tue, 28 Aug 2018 01:49:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726619AbeH1FiU (ORCPT ); Tue, 28 Aug 2018 01:38:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40286 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725724AbeH1FiU (ORCPT ); Tue, 28 Aug 2018 01:38: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 11B9F20E19; Tue, 28 Aug 2018 01:49:06 +0000 (UTC) Received: from lhg.nay.redhat.com (unknown [10.66.129.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7277C2166B41; Tue, 28 Aug 2018 01:49:04 +0000 (UTC) From: Honggang LI To: hal@dev.mellanox.co.il Cc: linux-rdma@vger.kernel.org, Honggang Li Subject: [PATCH 5/5] osmtest.c: osmtest_parse_path fix resource leak in error path Date: Tue, 28 Aug 2018 09:48:34 +0800 Message-Id: <20180828014834.3046-5-honli@redhat.com> In-Reply-To: <20180828014834.3046-4-honli@redhat.com> References: <20180828014834.3046-1-honli@redhat.com> <20180828014834.3046-2-honli@redhat.com> <20180828014834.3046-3-honli@redhat.com> <20180828014834.3046-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.2]); Tue, 28 Aug 2018 01:49:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 28 Aug 2018 01:49:06 +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): [#def13] opensm-3.3.20/osmtest/osmtest.c:6994: alloc_fn: Storage is returned from allocation function "path_new". opensm-3.3.20/osmtest/include/osmtest_subnet.h:254:2: alloc_fn: Storage is returned from allocation function "malloc". opensm-3.3.20/osmtest/include/osmtest_subnet.h:254:2: var_assign: Assigning: "p_obj" = "malloc(192UL)". opensm-3.3.20/osmtest/include/osmtest_subnet.h:256:3: noescape: Resource "p_obj" is not freed or pointed-to in function "memset". [Note: The source code implementation of the function has been overridden by a builtin model.] opensm-3.3.20/osmtest/include/osmtest_subnet.h:257:2: return_alloc: Returning allocated memory "p_obj". opensm-3.3.20/osmtest/osmtest.c:6994: var_assign: Assigning: "p_path" = storage returned from "path_new()". opensm-3.3.20/osmtest/osmtest.c:7136: leaked_storage: Variable "p_path" going out of scope leaks the storage it points to. |# 7134| Exit: |# 7135| OSM_LOG_EXIT(&p_osmt->log); |# 7136|-> return (status); |# 7137| } |# 7138| Signed-off-by: Honggang Li --- osmtest/osmtest.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osmtest/osmtest.c b/osmtest/osmtest.c index e6f91a81..8015bcec 100644 --- a/osmtest/osmtest.c +++ b/osmtest/osmtest.c @@ -7006,6 +7006,7 @@ osmtest_parse_path(IN osmtest_t * const p_osmt, OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 0127: " "Unexpected end of file\n"); status = IB_ERROR; + path_delete(p_path); goto Exit; } @@ -7116,6 +7117,7 @@ osmtest_parse_path(IN osmtest_t * const p_osmt, if (got_error) { status = IB_ERROR; + path_delete(p_path); goto Exit; } /*