From patchwork Fri Oct 12 08:25:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: robbieko X-Patchwork-Id: 10638025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE8491869 for ; Fri, 12 Oct 2018 08:25:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFBBF2BD0E for ; Fri, 12 Oct 2018 08:25:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3BC42BD18; Fri, 12 Oct 2018 08:25:45 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 259A62BD0E for ; Fri, 12 Oct 2018 08:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727524AbeJLP5B (ORCPT ); Fri, 12 Oct 2018 11:57:01 -0400 Received: from synology.com ([59.124.61.242]:44577 "EHLO synology.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727484AbeJLP5A (ORCPT ); Fri, 12 Oct 2018 11:57:00 -0400 Received: from localhost.localdomain (unknown [10.13.20.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by synology.com (Postfix) with ESMTPSA id CCEC41B6388B; Fri, 12 Oct 2018 16:25:40 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1539332740; bh=YjEqG2BBHBkMENmLjuKna+75e7Uc+kcPPTJzuiWBwko=; h=From:To:Cc:Subject:Date; b=RhWGKIH3l+lXqGfqZLwfSvV+0opMJXO/T1xquU9XVagEQ9TvfAbwe1LI6BJ/ZHryA 5AR4kJhle8U2RXfpkpuD+vbWJYFBLg1o7hRJUmB9M5E6kJu0bQ45G78CW6xXv167V8 ArwqkEk+tYSIADGUH8SJhMRq5bMs5LidY/D5ffEY= From: robbieko To: linux-btrfs@vger.kernel.org Cc: Robbie Ko Subject: [PATCH] btrfs-progs: super-recover: fix double free fs_devices memory Date: Fri, 12 Oct 2018 16:25:23 +0800 Message-Id: <1539332723-5868-1-git-send-email-robbieko@synology.com> X-Mailer: git-send-email 1.9.1 X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no 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 From: Robbie Ko super-recover collects btrfs devices information using existed functions scan_one_devices(). Problem is fs_devices is freed twice. One in __open_ctree_fd() when error happens and the other in btrfs_close_devices(recover.fs_devices) when root is NULL. Commit "30fd6f2e92695c355c8f76b8887cd4fade60cdac" add force-close all opened device before program exit, to avoid memory leak in all btrfs sub-command. Therefore, there is an unnecessary freed of fs_devices in btrfs_recover_superblocks. Fix this problem by remove unnecessary freed of fs_devices. Signed-off-by: Robbie Ko --- super-recover.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/super-recover.c b/super-recover.c index 880fd77..86b3df9 100644 --- a/super-recover.c +++ b/super-recover.c @@ -292,9 +292,6 @@ int btrfs_recover_superblocks(const char *dname, no_recover: recover_err_str(ret); free_recover_superblock(&recover); - /* check if we have freed fs_devices in close_ctree() */ - if (!root) - btrfs_close_devices(recover.fs_devices); return ret; }