Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp329263pxb; Wed, 18 Aug 2021 03:29:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGe8cFj8+3K1ZAG3KqZp6I04TuE8xijvDB2dZG1KcMw4psxlD6ABDOjs4J6vhU0vfTKncG X-Received: by 2002:a17:906:a94f:: with SMTP id hh15mr8967028ejb.297.1629282581545; Wed, 18 Aug 2021 03:29:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629282581; cv=none; d=google.com; s=arc-20160816; b=t51klytE67l4zmiXrELhhTguz0077d6ot3ICE7h1m8F3m4GGagbpE3tHwX5bMtl6bv d/ON/q6ASHHFhox9ZRpZuG/3BLr+ndG81TxGD07h3s5Iuc2oiy52SeMsf9j5wWOZy0sh 3aU8gE+I93xHTj0HkTe1Ov44nhpwm7qNB6jxvZwOPazdWUTZOZtOVvu3K8EhJTXGiFWA nJp9aWs4ZeLYeVah/lc5RT2RCafTl20g/B7jCiIThHg5YIxJirDYc17rVpPyLAjZ2mpY cqmP6pUKu9J3YVUO6Tt+p6jcDnqU1PFc+Ec9jTUX8yLt43bziVaJcmmYRm92k+mqDZcP 8YxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CIWpHyvhjM0v5hQGy4X7aU8xDXyHu3qVpUT347taFHQ=; b=UiZUp0+uYfx0AYSDdOPXLvDeQwPL2sWvTZpckPGXNkC/Pvyzzr/L1ZChhq67D+1E8f QTmetbccP2nSE4Gk9L+qQFBBRkmnMMKDp7tqEW/EOvDAKVRJZl0EXcy/H6QbBM3kVHxV dvoTphrmyCPwl7EHUH4/0cNwpyEpJZkW69oJw+/wrnbK9wSbroSJxDuJDctQLOuQq3o6 oqI0qyrBFmG9d2Ug8k+VcuW7tRmtZzAM7UpAadaMSwzJclqwh0qEq91CG+Hs9aXDDzVb 35iewDScbVix0lGyDAnod460JB4QQsDQTtRmImFGzsHI8hlliGeroG451jbhOg2k3Ppm xHPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EXvhJ9Nu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si4964634edr.106.2021.08.18.03.29.17; Wed, 18 Aug 2021 03:29:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EXvhJ9Nu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233576AbhHRK1J (ORCPT + 99 others); Wed, 18 Aug 2021 06:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbhHRK1H (ORCPT ); Wed, 18 Aug 2021 06:27:07 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36BD1C061764 for ; Wed, 18 Aug 2021 03:26:32 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id c17so1778150pgc.0 for ; Wed, 18 Aug 2021 03:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CIWpHyvhjM0v5hQGy4X7aU8xDXyHu3qVpUT347taFHQ=; b=EXvhJ9Nu2nrBbZ6Kanq7eyBFqYWQXpGM8xkALu2XfED/27p+Qdi133Et62KZ/DzHRb TqwgZhrIttVm/05nWTZ6rB+8vnGrIi+rgaG3nwStlHVoJdOSIN2ZpfAh8TB6ASZq3sJw hQJX1LdAz/RgcgVaor/da3Or9X33Nkt8BU9uRiYpHJOQ6e/BKcoOm9BLAibYFkAYgqIG K38BAVmotQm4KpKIgnJo2faCP5Dlu/Y5drsLnA4jCNFbg9WNUUf54j79XrUdtSHukh+q WRDEegQijaTjtJ/77c+JdA6zlYmAmhHC4B9F8hhfdgNGPv0FJFw7WdxQ/yCY4N4NAtJN 0nng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=CIWpHyvhjM0v5hQGy4X7aU8xDXyHu3qVpUT347taFHQ=; b=lTLCeQxLMV8Vt5vu42Yn78BOPpEyAaRaC/r2vGqOglbVDU3LatLBeHoUDLXaPY/DF0 LlG/m86NTm/Xhrbg6WztONeWO6FEOg5yFcG4qAEGqQLkmTikxd5RATriu7x+xwKSRrjk uo7y6jSyBcvMS9pXMEWI42ml22GeSgDJgyHNOXO7o58HNlkHj46XTJZXbxZBuyuRwr5N 5UGNhH1EhMpn0SnJathxGDJu4D28c9vbmHc/A45wQ5ei2QDToTOQzsHC3m9gt2jPCL0m W8em5Lj1I7yiNwO9Z8Da9pC1+DKrnzav7ZXNd+bUy9Sxk0ilWw1VPlRXO6cLbIrVy0UG PTkw== X-Gm-Message-State: AOAM5322muvduWsuzWD0ieo2XN3f+cqKIvBOmjmpgzQSu5Z7+S+zPPJv nLXqTy6spJ6skM9QOEXVslo= X-Received: by 2002:a62:65c7:0:b029:3c3:4eff:1b26 with SMTP id z190-20020a6265c70000b02903c34eff1b26mr8345347pfb.48.1629282391731; Wed, 18 Aug 2021 03:26:31 -0700 (PDT) Received: from localhost.localdomain ([154.16.166.182]) by smtp.gmail.com with ESMTPSA id c12sm5396258pfl.56.2021.08.18.03.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 03:26:31 -0700 (PDT) From: Dongliang Mu To: Dave Kleikamp Cc: Dongliang Mu , jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] JFS: fix memleak in jfs_mount Date: Wed, 18 Aug 2021 18:25:58 +0800 Message-Id: <20210818102612.864127-1-mudongliangabcd@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In jfs_mount, when diMount(ipaimap2) fails, it goes to errout35. However, the following code does not free ipaimap2 allocated by diReadSpecial. Fix this by refactoring the error handling code of jfs_mount. To be specific, modify the lable name and free ipaimap2 when the above error ocurrs. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Dongliang Mu --- fs/jfs/jfs_mount.c | 53 +++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/fs/jfs/jfs_mount.c b/fs/jfs/jfs_mount.c index 5d7d7170c03c..638a4ecc4069 100644 --- a/fs/jfs/jfs_mount.c +++ b/fs/jfs/jfs_mount.c @@ -81,14 +81,14 @@ int jfs_mount(struct super_block *sb) * (initialize mount inode from the superblock) */ if ((rc = chkSuper(sb))) { - goto errout20; + return rc; } ipaimap = diReadSpecial(sb, AGGREGATE_I, 0); if (ipaimap == NULL) { jfs_err("jfs_mount: Failed to read AGGREGATE_I"); rc = -EIO; - goto errout20; + goto out; } sbi->ipaimap = ipaimap; @@ -99,7 +99,7 @@ int jfs_mount(struct super_block *sb) */ if ((rc = diMount(ipaimap))) { jfs_err("jfs_mount: diMount(ipaimap) failed w/rc = %d", rc); - goto errout21; + goto err_ipaimap; } /* @@ -108,7 +108,7 @@ int jfs_mount(struct super_block *sb) ipbmap = diReadSpecial(sb, BMAP_I, 0); if (ipbmap == NULL) { rc = -EIO; - goto errout22; + goto err_umount_ipaimap; } jfs_info("jfs_mount: ipbmap:0x%p", ipbmap); @@ -120,7 +120,7 @@ int jfs_mount(struct super_block *sb) */ if ((rc = dbMount(ipbmap))) { jfs_err("jfs_mount: dbMount failed w/rc = %d", rc); - goto errout22; + goto err_ipbmap; } /* @@ -139,7 +139,7 @@ int jfs_mount(struct super_block *sb) if (!ipaimap2) { jfs_err("jfs_mount: Failed to read AGGREGATE_I"); rc = -EIO; - goto errout35; + goto err_umount_ipbmap; } sbi->ipaimap2 = ipaimap2; @@ -151,7 +151,7 @@ int jfs_mount(struct super_block *sb) if ((rc = diMount(ipaimap2))) { jfs_err("jfs_mount: diMount(ipaimap2) failed, rc = %d", rc); - goto errout35; + goto err_ipaimap2; } } else /* Secondary aggregate inode table is not valid */ @@ -168,7 +168,7 @@ int jfs_mount(struct super_block *sb) jfs_err("jfs_mount: Failed to read FILESYSTEM_I"); /* open fileset secondary inode allocation map */ rc = -EIO; - goto errout40; + goto err_umount_ipaimap2; } jfs_info("jfs_mount: ipimap:0x%p", ipimap); @@ -178,41 +178,32 @@ int jfs_mount(struct super_block *sb) /* initialize fileset inode allocation map */ if ((rc = diMount(ipimap))) { jfs_err("jfs_mount: diMount failed w/rc = %d", rc); - goto errout41; + goto err_ipimap; } - goto out; + return rc; /* * unwind on error */ - errout41: /* close fileset inode allocation map inode */ +err_ipimap: + /* close fileset inode allocation map inode */ diFreeSpecial(ipimap); - - errout40: /* fileset closed */ - +err_umount_ipaimap2: /* close secondary aggregate inode allocation map */ - if (ipaimap2) { - diUnmount(ipaimap2, 1); - diFreeSpecial(ipaimap2); - } - - errout35: - - /* close aggregate block allocation map */ + if (ipaimap2) diUnmount(ipaimap2, 1); +err_ipaimap2: + /* close aggregate inodes */ + if (ipaimap2) diFreeSpecial(ipaimap2); +err_umount_ipbmap: /* close aggregate block allocation map */ dbUnmount(ipbmap, 1); +err_ipbmap: /* close aggregate inodes */ diFreeSpecial(ipbmap); - - errout22: /* close aggregate inode allocation map */ - +err_umount_ipaimap: /* close aggregate inode allocation map */ diUnmount(ipaimap, 1); - - errout21: /* close aggregate inodes */ +err_ipaimap: /* close aggregate inodes */ diFreeSpecial(ipaimap); - errout20: /* aggregate closed */ - - out: - +out: if (rc) jfs_err("Mount JFS Failure: %d", rc); -- 2.25.1