From patchwork Mon May 30 21:19:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 830982 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p4ULKRE0004176 for ; Mon, 30 May 2011 21:20:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754679Ab1E3VUY (ORCPT ); Mon, 30 May 2011 17:20:24 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:54972 "EHLO smtp.gentoo.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754425Ab1E3VUX (ORCPT ); Mon, 30 May 2011 17:20:23 -0400 Received: from gentoo.org (unknown [178.125.169.231]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: slyfox) by smtp.gentoo.org (Postfix) with ESMTPSA id 8BDA11B4010; Mon, 30 May 2011 21:20:21 +0000 (UTC) Received: by gentoo.org (sSMTP sendmail emulation); Tue, 31 May 2011 00:20:16 +0300 From: Sergei Trofimovich To: Chris Mason Cc: linux-btrfs@vger.kernel.org, Sergei Trofimovich Subject: [PATCH 8/9] mkfs.btrfs: fix memory leak caused by 'scandir()' calls Date: Tue, 31 May 2011 00:19:07 +0300 Message-Id: <1306790348-9553-9-git-send-email-slyfox@gentoo.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1306790348-9553-1-git-send-email-slyfox@gentoo.org> References: <1306790348-9553-1-git-send-email-slyfox@gentoo.org> 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 (demeter1.kernel.org [140.211.167.41]); Mon, 30 May 2011 21:20:27 +0000 (UTC) Signed-off-by: Sergei Trofimovich --- mkfs.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/mkfs.c b/mkfs.c index c8b19c1..73c898b 100644 --- a/mkfs.c +++ b/mkfs.c @@ -468,6 +468,15 @@ static int directory_select(const struct direct *entry) return 1; } +static void free_namelist(struct direct **files, int count) +{ + int i; + + for (i = 0; i < count; ++i) + free(files[i]); + free (files); +} + static u64 calculate_dir_inode_size(char *dirname) { int count, i; @@ -481,6 +490,8 @@ static u64 calculate_dir_inode_size(char *dirname) dir_inode_size += strlen(cur_file->d_name); } + free_namelist(files, count); + dir_inode_size *= 2; return dir_inode_size; } @@ -971,6 +982,7 @@ static int traverse_directory(struct btrfs_trans_handle *trans, } } + free_namelist(files, count); free(parent_dir_entry->path); free(parent_dir_entry); @@ -980,6 +992,7 @@ static int traverse_directory(struct btrfs_trans_handle *trans, return 0; fail: + free_namelist(files, count); free(parent_dir_entry->path); free(parent_dir_entry); return -1;