summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendrabhat@gluster.com>2011-06-30 06:59:12 +0000
committerAnand Avati <avati@gluster.com>2011-07-01 01:26:16 -0700
commita21c3bb99e5ad59e8e9ec0a050ce8617ce3fe167 (patch)
tree64dac96d5f5fc565ea4d7e6c3d070408de4ee0cc /libglusterfs
parent64316c419f013464641b84900acc0ff4eeeaf2ae (diff)
inode table: avoid memleak by freeing the allocated structures incase of failure
Signed-off-by: Raghavendra Bhat <raghavendrabhat@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 3103 (memleak in inode table creation) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=3103
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/inode.c58
-rw-r--r--libglusterfs/src/inode.h3
2 files changed, 28 insertions, 33 deletions
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c
index 90b62a2f497..fef678bd261 100644
--- a/libglusterfs/src/inode.c
+++ b/libglusterfs/src/inode.c
@@ -663,14 +663,6 @@ inode_grep (inode_table_t *table, inode_t *parent, const char *name)
return inode;
}
-
-inode_t *
-inode_get (inode_table_t *table, ino_t ino, uint64_t gen)
-{
- return NULL;
-}
-
-
int
__is_root_gfid (uuid_t gfid)
{
@@ -1174,7 +1166,7 @@ inode_table_t *
inode_table_new (size_t lru_limit, xlator_t *xl)
{
inode_table_t *new = NULL;
- int ret = 0;
+ int ret = -1;
int i = 0;
new = (void *)GF_CALLOC(1, sizeof (*new), gf_common_mt_inode_table_t);
@@ -1193,41 +1185,30 @@ inode_table_new (size_t lru_limit, xlator_t *xl)
new->inode_pool = mem_pool_new (inode_t, lru_limit);
- if (!new->inode_pool) {
- GF_FREE (new);
- return NULL;
- }
+ if (!new->inode_pool)
+ goto out;
new->dentry_pool = mem_pool_new (dentry_t, lru_limit);
- if (!new->dentry_pool) {
- GF_FREE (new);
- return NULL;
- }
+ if (!new->dentry_pool)
+ goto out;
new->inode_hash = (void *)GF_CALLOC (65536,
sizeof (struct list_head),
gf_common_mt_list_head);
- if (!new->inode_hash) {
- GF_FREE (new);
- return NULL;
- }
+ if (!new->inode_hash)
+ goto out;
new->name_hash = (void *)GF_CALLOC (new->hashsize,
sizeof (struct list_head),
gf_common_mt_list_head);
- if (!new->name_hash) {
- GF_FREE (new->inode_hash);
- GF_FREE (new);
- return NULL;
- }
+ if (!new->name_hash)
+ goto out;
new->fd_mem_pool = mem_pool_new (fd_t, 16384);
- if (!new->fd_mem_pool) {
- GF_FREE (new->inode_hash);
- GF_FREE (new);
- }
+ if (!new->fd_mem_pool)
+ goto out;
for (i = 0; i < 65536; i++) {
INIT_LIST_HEAD (&new->inode_hash[i]);
@@ -1252,6 +1233,23 @@ inode_table_new (size_t lru_limit, xlator_t *xl)
pthread_mutex_init (&new->lock, NULL);
+ ret = 0;
+out:
+ if (ret) {
+ if (new) {
+ if (new->inode_hash)
+ GF_FREE (new->inode_hash);
+ if (new->name_hash)
+ GF_FREE (new->name_hash);
+ if (new->dentry_pool)
+ mem_pool_destroy (new->dentry_pool);
+ if (new->inode_pool)
+ mem_pool_destroy (new->inode_pool);
+ GF_FREE (new);
+ new = NULL;
+ }
+ }
+
return new;
}
diff --git a/libglusterfs/src/inode.h b/libglusterfs/src/inode.h
index 7eea0c5a389..db2933f8fc1 100644
--- a/libglusterfs/src/inode.h
+++ b/libglusterfs/src/inode.h
@@ -144,9 +144,6 @@ inode_t *
inode_grep (inode_table_t *table, inode_t *parent, const char *name);
inode_t *
-inode_get (inode_table_t *table, ino_t ino, uint64_t gen);
-
-inode_t *
inode_find (inode_table_t *table, uuid_t gfid);
int