Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1039476ybt; Tue, 7 Jul 2020 06:30:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuwDkbiNagrKMMPNU6SQGosB5KbQS/hN90im1jeQdgomo3Swh7kSbh8ds4EChjudaODBsv X-Received: by 2002:a17:906:e210:: with SMTP id gf16mr37930727ejb.386.1594128602588; Tue, 07 Jul 2020 06:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594128602; cv=none; d=google.com; s=arc-20160816; b=aIJZh1Jq7AQHGr5tgNExtKMifwRfZQYpQgJuwGeOtbu3+L/yQPhJnDumuRgP5p5VW7 bAV7Xz9EeQkAiwGXd6OFUsfko7ePQczz419/pDzCw2UxbOqQo6UzaQJDmDxKqvsM49U2 pHTN3f+VB2JT5xklTSdSTXXka5oPhDxTSWLG3iSP2KjaHZhNWxA6GJv2AxXXSfPkxGcG Mi/wnnaYVjdwL3SPRuYZBVtAr9pP7lQliMw/ZZT2Qzog9LL5m6P6h5MT8MhDMH6D4euh gQXSQFTaYjUdI5n5u/NPdkPGFsZnJc6dB1wKnmB8245pj/GUUyZjje09cqEilGfaHsM5 AYZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=bpqV8ZGEfDigVwyXYOylVCt2pIZCMYHJKK1J8Iop6Ek=; b=q+D0IAlkHKN4MBFFD1EFAaB5zIB/9k4mH8MBvn9+3KNM0vu5abR6f8/tWDwhh+JIiQ toStcfwpqMQMsF3d5/15e+DuPbl90kQerHkDiHtcf9tn2ixD1HvxNIfkCfbCMe+qEPm3 9RyolyI6ZO3i2TlQiDodWRROFqFu2gxeityWnPNTktJwHhfmljEF3fo1Xtr9cBuMO4gv rH2FXdnKgmfy6r8OyE11eNu2NMsvR/5kTQj+d7RE/Y4yXyTTkYlKq84amjj7sPzW4UC3 RFfRDl46c2nfOgd4nEH7kt26evX1ziRcuG1NoIIXbEBrnId+36dKYH2nzbXGG8woHIKq DOjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Wld/FDLm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ck17si14134958edb.508.2020.07.07.06.29.38; Tue, 07 Jul 2020 06:30:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Wld/FDLm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728184AbgGGN3V (ORCPT + 99 others); Tue, 7 Jul 2020 09:29:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:46600 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727044AbgGGN3V (ORCPT ); Tue, 7 Jul 2020 09:29:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594128560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=bpqV8ZGEfDigVwyXYOylVCt2pIZCMYHJKK1J8Iop6Ek=; b=Wld/FDLmGkEFamjwzP97csEwuh729A/r4xzGZHHYHoZ9Ut1SLlQVbuqs5mIlZjxcf2ZL6E A9SW79ltoIrZhJluFDY4x2eNuuTrLv88y0xQWrXE4jHzoS55JHax8Q3dTp54Qrs/rI3kjG b3k5I9X7PAFL+rHok5QTEclricIfb18= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-6He1-iJlMpGx-i6_jZ8hWA-1; Tue, 07 Jul 2020 09:29:16 -0400 X-MC-Unique: 6He1-iJlMpGx-i6_jZ8hWA-1 Received: by mail-qk1-f198.google.com with SMTP id i3so22333270qkf.0 for ; Tue, 07 Jul 2020 06:29:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bpqV8ZGEfDigVwyXYOylVCt2pIZCMYHJKK1J8Iop6Ek=; b=QRiiuKzZZd5+GFCMeM+KNPA5ctoFx4wdn8PfsiVk2BZSEFRID7T9p64kjQtHp5ZSaA ZhYHejR7WruG0B6pCiWc0SsJhA0pEw1+qb6N+u1nCdA9sk+eEF/CIuHPhYX4FeAnWdJ4 BrZ2AQmypAWzH/FQ9UvPzefA1XReJdSWFh1+rAUuJs7n30qxUwCf37EKRzbHrd97uvDt CBg/v/QGq5sw7CEAKfHGcg+fUrNleLws48RJyrsrfsai64LEHJ3hFu9odZXgvtoQ+AXt GJXx9ZHBgt/eHOQaJEHk+8XLTdrRy2WBS3aVDy5weSIQVIQelIuz9UTS5rEhayYjHZc6 s1TA== X-Gm-Message-State: AOAM5306nk+mEOuYLEhq2Sk7RMvqiCg7JRiVq2Tz/nNxeodCHPJk/Se+ qeu8vc/nkXA8wzjFRooJQNVOj6nJNXOTWLbSPjJVTBqrNDTfpjqJMdItA7N2ySRdc5YqXlnGnCH 7xQD8BbGWPaSrSprOnHdMcf// X-Received: by 2002:ac8:6d24:: with SMTP id r4mr30664727qtu.43.1594128555741; Tue, 07 Jul 2020 06:29:15 -0700 (PDT) X-Received: by 2002:ac8:6d24:: with SMTP id r4mr30664700qtu.43.1594128555462; Tue, 07 Jul 2020 06:29:15 -0700 (PDT) Received: from trix.remote.csb (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id g41sm28492912qtb.37.2020.07.07.06.29.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 06:29:14 -0700 (PDT) From: trix@redhat.com To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Rix Subject: [PATCH] btrfs : fix memory leak in add_block_entry Date: Tue, 7 Jul 2020 06:29:08 -0700 Message-Id: <20200707132908.10987-1-trix@redhat.com> X-Mailer: git-send-email 2.18.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Rix clang static analysis flags this error fs/btrfs/ref-verify.c:290:3: warning: Potential leak of memory pointed to by 're' [unix.Malloc] kfree(be); ^~~~~ The problem is in this block of code if (root_objectid) { struct root_entry *exist_re; exist_re = insert_root_entry(&exist->roots, re); if (exist_re) kfree(re); } There is no 'else' block freeing when root_objectid == 0 So add an 'else' Fixes: fd708b81d972 ("Btrfs: add a extent ref verify tool") Signed-off-by: Tom Rix --- fs/btrfs/ref-verify.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c index af92525dbb16..7f03dbe5b609 100644 --- a/fs/btrfs/ref-verify.c +++ b/fs/btrfs/ref-verify.c @@ -286,6 +286,8 @@ static struct block_entry *add_block_entry(struct btrfs_fs_info *fs_info, exist_re = insert_root_entry(&exist->roots, re); if (exist_re) kfree(re); + } else { + kfree(re); } kfree(be); return exist; -- 2.18.1