From patchwork Wed May 10 06:58:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Praveen K Pandey X-Patchwork-Id: 9719311 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 CFF0360236 for ; Wed, 10 May 2017 06:58:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0E99284E3 for ; Wed, 10 May 2017 06:58:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3C4228576; Wed, 10 May 2017 06:58:18 +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=-6.9 required=2.0 tests=BAYES_00,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 4A2B6284E3 for ; Wed, 10 May 2017 06:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751728AbdEJG6Q (ORCPT ); Wed, 10 May 2017 02:58:16 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:56152 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751561AbdEJG6P (ORCPT ); Wed, 10 May 2017 02:58:15 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v4A6n0QP009228 for ; Wed, 10 May 2017 02:58:15 -0400 Received: from e17.ny.us.ibm.com (e17.ny.us.ibm.com [129.33.205.207]) by mx0a-001b2d01.pphosted.com with ESMTP id 2abnqc0d7d-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 May 2017 02:58:14 -0400 Received: from localhost by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 May 2017 02:58:13 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e17.ny.us.ibm.com (146.89.104.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 May 2017 02:58:11 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v4A6wBMA42729538; Wed, 10 May 2017 06:58:11 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B6F8AE03B; Wed, 10 May 2017 02:57:59 -0400 (EDT) Received: from localhost.in.ibm.com (unknown [9.124.35.225]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 9D548AE034; Wed, 10 May 2017 02:57:58 -0400 (EDT) From: Praveen K Pandey To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, Praveen K Pandey Subject: [PATCH] btrfs-progs: record_orphan_data_extent: Fix memory leak Date: Wed, 10 May 2017 12:28:02 +0530 X-Mailer: git-send-email 2.5.5 X-TM-AS-GCONF: 00 x-cbid: 17051006-0040-0000-0000-00000337E970 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007042; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000209; SDB=6.00858552; UDB=6.00425412; IPR=6.00638017; BA=6.00005339; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015388; XFM=3.00000015; UTC=2017-05-10 06:58:12 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17051006-0041-0000-0000-0000072C10F7 Message-Id: <1494399482-15057-1-git-send-email-praveen@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-10_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1705100050 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 The nodes of the list at btrfs_root->orphan_data_extents are never freed causing memory to be leaked. This commit fixes the bug by freeing the nodes on all the btrfs_root->orphan_data_extents list. Signed-off-by: Praveen K Pandey --- cmds-check.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 0014bc2..cac94a8 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -9286,6 +9286,9 @@ static int check_extent_refs(struct btrfs_root *root, { struct extent_record *rec; struct cache_extent *cache; + struct btrfs_fs_info *fs_info; + struct btrfs_root *root_orphan_extent; + struct rb_node *rb_node; int ret = 0; int had_dups = 0; @@ -9439,6 +9442,26 @@ static int check_extent_refs(struct btrfs_root *root, rec->start + rec->max_size - 1); free(rec); } + /* + * Release memory of oprhan_data_extent + * which allocated while traversing in orphan_data_extents + */ + + fs_info = root->fs_info; + rb_node = rb_first(&fs_info->fs_root_tree); + while (rb_node) { + root_orphan_extent = container_of(rb_node, + struct btrfs_root, rb_node); + free_orphan_data_extents(&root_orphan_extent->orphan_data_extents); + rb_node = rb_next(rb_node); + } + free_orphan_data_extents(&fs_info->extent_root->orphan_data_extents); + free_orphan_data_extents(&fs_info->tree_root->orphan_data_extents); + free_orphan_data_extents(&fs_info->chunk_root->orphan_data_extents); + free_orphan_data_extents(&fs_info->dev_root->orphan_data_extents); + free_orphan_data_extents(&fs_info->csum_root->orphan_data_extents); + if (fs_info->quota_enabled) + free_orphan_data_extents(&fs_info->quota_root->orphan_data_extents); repair_abort: if (repair) { if (ret && ret != -EAGAIN) {