From patchwork Thu Jun 9 03:08:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12874787 X-Patchwork-Delegate: jes@trained-monkey.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CE42C433EF for ; Thu, 9 Jun 2022 03:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237441AbiFIDIo (ORCPT ); Wed, 8 Jun 2022 23:08:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232220AbiFIDIm (ORCPT ); Wed, 8 Jun 2022 23:08:42 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918EF14478F for ; Wed, 8 Jun 2022 20:08:41 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LJTX96j8TzgZLx; Thu, 9 Jun 2022 11:06:49 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 9 Jun 2022 11:08:39 +0800 Received: from [10.174.177.211] (10.174.177.211) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 9 Jun 2022 11:08:39 +0800 Message-ID: Date: Thu, 9 Jun 2022 11:08:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: [PATCH 4/5 v2] find_disk_attached_hba: fix memleak From: Wu Guanghao To: , , Mariusz Tkaczyk , Paul Menzel CC: , References: In-Reply-To: X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org If disk_path = diskfd_to_devpath(), we need free(disk_path) before return, otherwise there will be a memory leak Reported-by: Coverity Signed-off-by: Wu Guanghao Reviewed-by: Mariusz Tkaczyk --- super-intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.27.0 diff --git a/super-intel.c b/super-intel.c index ee9e112e..e94f3f65 100644 --- a/super-intel.c +++ b/super-intel.c @@ -701,12 +701,12 @@ static struct sys_dev* find_disk_attached_hba(int fd, const char *devname) for (elem = list; elem; elem = elem->next) if (path_attached_to_hba(disk_path, elem->path)) - return elem; + break; if (disk_path != devname) free(disk_path); - return NULL; + return elem; } static int find_intel_hba_capability(int fd, struct intel_super *super,