From patchwork Mon Apr 23 05:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10356139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 49A50601BE for ; Mon, 23 Apr 2018 05:08:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 315E4289AC for ; Mon, 23 Apr 2018 05:08:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 239DE289AF; Mon, 23 Apr 2018 05:08:26 +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 9C10D289AC for ; Mon, 23 Apr 2018 05:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751242AbeDWFIF (ORCPT ); Mon, 23 Apr 2018 01:08:05 -0400 Received: from mgwym02.jp.fujitsu.com ([211.128.242.41]:51168 "EHLO mgwym02.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751061AbeDWFIE (ORCPT ); Mon, 23 Apr 2018 01:08:04 -0400 Received: from yt-mxauth.gw.nic.fujitsu.com (unknown [192.168.229.68]) by mgwym02.jp.fujitsu.com with smtp id 107f_6d7e_d9d8f709_2993_425d_9224_8e572fcf599c; Mon, 23 Apr 2018 14:08:01 +0900 Received: from g01jpfmpwyt03.exch.g01.fujitsu.local (g01jpfmpwyt03.exch.g01.fujitsu.local [10.128.193.57]) by yt-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id 369F3AC00AD for ; Mon, 23 Apr 2018 14:08:00 +0900 (JST) Received: from g01jpexchyt38.g01.fujitsu.local (unknown [10.128.193.4]) by g01jpfmpwyt03.exch.g01.fujitsu.local (Postfix) with ESMTP id 2C17E46E62E for ; Mon, 23 Apr 2018 14:07:59 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 9f78a73288f5483fb6d9ec48213b9bde Subject: [RFC PATCH v4 1/6] btrfs-progs: sub list: Call rb_free_nodes() in error path From: Misono Tomohiro To: linux-btrfs References: <70590827-0c29-75ea-5e43-2e53264b3d4c@jp.fujitsu.com> Message-ID: Date: Mon, 23 Apr 2018 14:07:55 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <70590827-0c29-75ea-5e43-2e53264b3d4c@jp.fujitsu.com> Content-Language: en-US X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After btrfs_list_subvols() is called, root_lookup may hold some allocated memory area even if the function fails. Therefore rb_free_nodes() should be called. Signed-off-by: Tomohiro Misono --- btrfs-list.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/btrfs-list.c b/btrfs-list.c index e01c5899..50e5ce5f 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -1523,8 +1523,10 @@ int btrfs_list_subvols_print(int fd, struct btrfs_list_filter_set *filter_set, return ret; ret = btrfs_list_subvols(fd, &root_lookup); - if (ret) + if (ret) { + rb_free_nodes(&root_lookup.root, free_root_info); return ret; + } filter_and_sort_subvol(&root_lookup, &root_sort, filter_set, comp_set, top_id); @@ -1554,14 +1556,18 @@ int btrfs_get_toplevel_subvol(int fd, struct root_info *the_ri) return ret; ret = btrfs_list_subvols(fd, &rl); - if (ret) + if (ret) { + rb_free_nodes(&rl.root, free_root_info); return ret; + } rbn = rb_first(&rl.root); ri = rb_entry(rbn, struct root_info, rb_node); - if (ri->root_id != BTRFS_FS_TREE_OBJECTID) + if (ri->root_id != BTRFS_FS_TREE_OBJECTID) { + rb_free_nodes(&rl.root, free_root_info); return -ENOENT; + } memcpy(the_ri, ri, offsetof(struct root_info, path)); the_ri->path = strdup_or_null("/"); @@ -1585,8 +1591,10 @@ int btrfs_get_subvol(int fd, struct root_info *the_ri) return ret; ret = btrfs_list_subvols(fd, &rl); - if (ret) + if (ret) { + rb_free_nodes(&rl.root, free_root_info); return ret; + } rbn = rb_first(&rl.root); while(rbn) {