From patchwork Thu Oct 25 13:17:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 1644171 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id B721EDF2AB for ; Thu, 25 Oct 2012 13:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759488Ab2JYNR6 (ORCPT ); Thu, 25 Oct 2012 09:17:58 -0400 Received: from acsinet15.oracle.com ([141.146.126.227]:42530 "EHLO acsinet15.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756916Ab2JYNR5 (ORCPT ); Thu, 25 Oct 2012 09:17:57 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q9PDHqEx011767 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Oct 2012 13:17:52 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q9PDHp5a026710 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 25 Oct 2012 13:17:51 GMT Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q9PDHpAx021214; Thu, 25 Oct 2012 08:17:51 -0500 Received: from mapleapple-Compaq-Presario-CQ40-Notebook-PC.jp.oracle.com (/10.191.5.214) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Oct 2012 06:17:50 -0700 From: Liu Bo To: linux-btrfs@vger.kernel.org Cc: list.btrfs@jan-o-sch.net Subject: [PATCH] Btrfs: fix memory leak when cloning root's node Date: Thu, 25 Oct 2012 21:17:59 +0800 Message-Id: <1351171079-5950-1-git-send-email-bo.li.liu@oracle.com> X-Mailer: git-send-email 1.7.9.5 X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org After cloning root's node, we forgot to dec the src's ref which can lead to a memory leak. Signed-off-by: Liu Bo --- Jan, Please add this patch to your pull and notice Chris about it :) I didn't get this bug out since I didn't do rmmod yesterday... thanks, fs/btrfs/ctree.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index eba44b0..2afa585 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1261,16 +1261,19 @@ get_old_root(struct btrfs_root *root, u64 time_seq) tm = tree_mod_log_search(root->fs_info, logical, time_seq); if (old_root && tm && tm->op != MOD_LOG_KEY_REMOVE_WHILE_FREEING) { + struct extent_buffer *old; + btrfs_tree_read_unlock(root->node); free_extent_buffer(root->node); blocksize = btrfs_level_size(root, old_root->level); - eb = read_tree_block(root, logical, blocksize, 0); - if (!eb) { + old = read_tree_block(root, logical, blocksize, 0); + if (!old) { pr_warn("btrfs: failed to read tree block %llu from get_old_root\n", logical); WARN_ON(1); } else { - eb = btrfs_clone_extent_buffer(eb); + eb = btrfs_clone_extent_buffer(old); + free_extent_buffer(eb); } } else if (old_root) { btrfs_tree_read_unlock(root->node);