Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2221793pxj; Sun, 30 May 2021 18:27:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEmdyyiCbdQ6oY3AGgUobxP8d+u1V3vDjsTqpaCQQ4ExmmgfW6670q1kdN1T15K7X69SSk X-Received: by 2002:a17:906:7f06:: with SMTP id d6mr20450115ejr.189.1622424426354; Sun, 30 May 2021 18:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622424426; cv=none; d=google.com; s=arc-20160816; b=t6De+L+t1KFYBfz9KOcUNAPAR2P9m+/+9YgiCzbbrw4QlBtqkowxuWj7l1NZDDGNVD WspZ3yU/V+Akv37wPTjGGt2uAqQ2HNofJ2uOZRAoTjOo28FW8u2WZILovQJdmeLcDyHM bf+FqR9011Q7mXpyrmilOyT425EJ0p7pwxgmUif28zUJC87JY4BXY0An8JrKEhR1r3Yz QpPgquXRQ/2B3kZtdWJbQ8MBWFdV+X5fwVzZ5q0eB8+VT/+n/C7u+YfoZ+Rx+bGQAW4e nzopAUAV7q9IkVqYmRw34eslroF/8SPITd747KqUxL/BscUVaa9J2Djj23oWlkJAWgcA YKtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=DF1aK6inJwHAQKOJmZZblCd8Hk9hVFwCjzsBHPxC6aQ=; b=N9ACC0FedHVK2eTgsL7dQVZpvAgdC4ym/jHIQ37HX2Km/0KD7siYvTynbJmEknnymN H+qPEZ/kbZg86HymHq72XNyL9z01wwBSpqhmT+r331hs61E4KjcrfkzefGNZ/ycvEwcQ dp0FCTwQp/rx+E/s+ZrzNVVkDI6d6tgQaAfDBWhQTdPC0vWDdNj52VouOk+HhZe1gYTp nPAdm7RewLtRTsMyA37gLvpiaWe/C1zBkiHau3JxOlfL/3CnRBgefsg64Q3JprVd6R71 gpIFU0yh9QaBOzPl7etPwvxK65o3BcEhEiJnDChKYzvQ3H+Yn0jv26++xWFYDFSh5Mv3 1/sQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb8si13975929edb.249.2021.05.30.18.26.43; Sun, 30 May 2021 18:27:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229897AbhEaB2S (ORCPT + 99 others); Sun, 30 May 2021 21:28:18 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2414 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbhEaB2S (ORCPT ); Sun, 30 May 2021 21:28:18 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Ftcwv4cXZz67L7 for ; Mon, 31 May 2021 09:22:55 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 09:26:36 +0800 Received: from [10.174.179.184] (10.174.179.184) 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.2176.2; Mon, 31 May 2021 09:26:36 +0800 Subject: [PATCH V2 03/12] zap_sector: fix memory leak From: Wu Guanghao To: , =?UTF-8?B?0JHQu9Cw0LPQvtC00LDRgNC10L3QutC+INCQ0YDRgtGR0Lw=?= CC: , References: <00ad4a90-8a40-24c1-98d9-eb5f0da42436@huawei.com> Message-ID: <3fbdb06d-e897-72da-14c9-89ed680e070f@huawei.com> Date: Mon, 31 May 2021 09:26:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.1 MIME-Version: 1.0 In-Reply-To: <00ad4a90-8a40-24c1-98d9-eb5f0da42436@huawei.com> Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.184] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In zap_sector(), need free buf before return, otherwise it will cause memory leak. Signed-off-by: Wu Guanghao Signed-off-by: Zhiqiang Liu Reviewed-by: Wu Bo --- misc/mke2fs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/mke2fs.c b/misc/mke2fs.c index afbcf486..2f229534 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -585,8 +585,10 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect) else { magic = (unsigned int *) (buf + BSD_LABEL_OFFSET); if ((*magic == BSD_DISKMAGIC) || - (*magic == BSD_MAGICDISK)) + (*magic == BSD_MAGICDISK)) { + free(buf); return; + } } } --