From patchwork Tue May 2 03:17:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9707365 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 0011160245 for ; Tue, 2 May 2017 03:17:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6A3E281C3 for ; Tue, 2 May 2017 03:17:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA9082833B; Tue, 2 May 2017 03:17:41 +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 ADFA328338 for ; Tue, 2 May 2017 03:17:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751171AbdEBDRf (ORCPT ); Mon, 1 May 2017 23:17:35 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:16118 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750902AbdEBDRc (ORCPT ); Mon, 1 May 2017 23:17:32 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18359402" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 02 May 2017 11:17:30 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id C2F4C47E6343; Tue, 2 May 2017 11:17:28 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 2 May 2017 11:17:26 +0800 From: Qu Wenruo To: , Subject: [PATCH] btrfs-progs: check: Fix memory leak in check_chunks_and_extents Date: Tue, 2 May 2017 11:17:25 +0800 Message-ID: <20170502031725.10312-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.12.2 MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: C2F4C47E6343.AF42B X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com 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 fsck/003-shift-offsets makes valgrinds complaining about memory leaks. ==5910== ==5910== HEAP SUMMARY: ==5910== in use at exit: 1,112 bytes in 11 blocks ==5910== total heap usage: 161 allocs, 150 frees, 164,800 bytes allocated ==5910== ==5910== 216 (72 direct, 144 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 5 ==5910== at 0x4C2AF1F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==5910== by 0x4815A3: add_root_item_to_list (cmds-check.c:9683) ==5910== by 0x481CE2: check_chunks_and_extents (cmds-check.c:9886) ==5910== by 0x48888B: cmd_check (cmds-check.c:12977) ==5910== by 0x40A8C5: main (btrfs.c:246) ==5910== The check_chunks_and_extents() memory leaks are caused by not freeing added root items of normal_trees and dropping_trees. Signed-off-by: Qu Wenruo --- cmds-check.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmds-check.c b/cmds-check.c index 17b7efbf..897b1587 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -9972,6 +9972,8 @@ out: free_extent_cache_tree(&pending); free_extent_cache_tree(&reada); free_extent_cache_tree(&nodes); + free_root_item_list(&normal_trees); + free_root_item_list(&dropping_trees); return ret; loop: free_corrupt_blocks_tree(root->fs_info->corrupt_blocks);