From patchwork Thu Sep 1 14:33:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Calleja X-Patchwork-Id: 1119332 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p81EYDef015257 for ; Thu, 1 Sep 2011 14:34:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757662Ab1IAOeJ (ORCPT ); Thu, 1 Sep 2011 10:34:09 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:41011 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757644Ab1IAOeH (ORCPT ); Thu, 1 Sep 2011 10:34:07 -0400 Received: by wyh22 with SMTP id 22so1028177wyh.19 for ; Thu, 01 Sep 2011 07:34:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:reply-to:to:subject:date:user-agent:cc:mime-version :content-type:content-transfer-encoding:message-id; bh=tBNMAY+Cedi/R42cL2MP3izXF0oOZGYA4BBc3CbYX8M=; b=cBD7YMLv/cSU6ypLRIdwMwuH4L+O6G6d6UFe2y+WyKXAnqhfGIQbu6yOT8iohIkBY3 Y8kaVtapKfQFGFkC+d2k6+8V22tC1Y1+sipg5Bnj3nn1ua/iOp3osGR+nw4mNJ/1xkrF bQxURkWFtBCstj1sy8fu1aHuHXJGlR2Va874Y= Received: by 10.227.19.194 with SMTP id c2mr296339wbb.65.1314887646540; Thu, 01 Sep 2011 07:34:06 -0700 (PDT) Received: from fedora.localnet (60.Red-88-1-167.dynamicIP.rima-tde.net [88.1.167.60]) by mx.google.com with ESMTPS id fd4sm89773wbb.13.2011.09.01.07.34.03 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Sep 2011 07:34:05 -0700 (PDT) From: Diego Calleja Reply-To: diegocg@gmail.com To: Chris Mason Subject: [PATCH] btrfs: fix memory leak in btrfs_defrag_file Date: Thu, 1 Sep 2011 16:33:57 +0200 User-Agent: KMail/1.13.7 (Linux/3.1.0-rc4-00415-g9e79e3e; KDE/4.6.5; x86_64; ; ) Cc: linux-btrfs@vger.kernel.org MIME-Version: 1.0 Message-Id: <201109011633.57877.diegocg@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Thu, 01 Sep 2011 14:34:14 +0000 (UTC) kmemleak found this: unreferenced object 0xffff8801b64af968 (size 512): comm "btrfs-cleaner", pid 3317, jiffies 4306810886 (age 903.272s) hex dump (first 32 bytes): 00 82 01 07 00 ea ff ff c0 83 01 07 00 ea ff ff ................ 80 82 01 07 00 ea ff ff c0 87 01 07 00 ea ff ff ................ backtrace: [] kmemleak_alloc+0x5c/0xc0 [] kmem_cache_alloc_trace+0x163/0x240 [] btrfs_defrag_file+0xf0/0xb20 [] btrfs_run_defrag_inodes+0x165/0x210 [] cleaner_kthread+0x177/0x190 [] kthread+0x8d/0xa0 [] kernel_thread_helper+0x4/0x10 [] 0xffffffffffffffff "pages" is not always freed. Fix it removing the unnecesary additional return. Signed-off-by: Diego Calleja Reviewed-by: Li Zefan --- fs/btrfs/ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux/fs/btrfs/ioctl.c =================================================================== --- linux.orig/fs/btrfs/ioctl.c +++ linux/fs/btrfs/ioctl.c @@ -1130,17 +1130,15 @@ int btrfs_defrag_file(struct inode *inod disk_super = &root->fs_info->super_copy; features = btrfs_super_incompat_flags(disk_super); if (range->compress_type == BTRFS_COMPRESS_LZO) { features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO; btrfs_set_super_incompat_flags(disk_super, features); } - if (!file) - kfree(ra); - return defrag_count; + ret = defrag_count; out_ra: if (!file) kfree(ra); kfree(pages); return ret; }