btrfsprogs/0123-mkfs.btrfs-fix-memory-leak-caused-by-scandir-calls.patch
Dirk Mueller a0e284e535 - add support for currently available kernel features:
- add scrub subcommand
  - scan /proc/partitions by default (or use --all-devices for all)
  - mkfs fixes and improvements
  - documentation fixes

- update from git:
  - add btrfs-select-super utility
  - add btrfs-label utility
  - allow mixed data+metadata (option --mixed)
  - allow populating new filesystem with files (option --rootdir)
  - allow discard support in mkfs
  - lzo support
  - deprecate 'btrfsctl' 'btrfs-vol' 'btrfs-show'
  - other bugfixes and documentation improvements

OBS-URL: https://build.opensuse.org/package/show/filesystems/btrfsprogs?expand=0&rev=104
2011-07-13 14:48:36 +00:00

64 lines
1.4 KiB
Diff

From 52ba789b8b6d316df29639379daa764ed630718b Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <slyfox@gentoo.org>
Date: Sat, 4 Jun 2011 11:19:23 +0300
Subject: [PATCH 23/28] mkfs.btrfs: fix memory leak caused by 'scandir()'
calls
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
mkfs.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/mkfs.c b/mkfs.c
index 5701c0a..b93b874 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -468,6 +468,18 @@ static int directory_select(const struct direct *entry)
return 1;
}
+static void free_namelist(struct direct **files, int count)
+{
+ int i;
+
+ if (count < 0)
+ return;
+
+ for (i = 0; i < count; ++i)
+ free(files[i]);
+ free(files);
+}
+
static u64 calculate_dir_inode_size(char *dirname)
{
int count, i;
@@ -481,6 +493,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 +985,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 +995,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;
--
1.7.5.2.353.g5df3e