From a21c3bb99e5ad59e8e9ec0a050ce8617ce3fe167 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Thu, 30 Jun 2011 06:59:12 +0000 Subject: inode table: avoid memleak by freeing the allocated structures incase of failure Signed-off-by: Raghavendra Bhat Signed-off-by: Anand Avati BUG: 3103 (memleak in inode table creation) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=3103 --- libglusterfs/src/inode.c | 58 +++++++++++++++++++++++------------------------- libglusterfs/src/inode.h | 3 --- 2 files changed, 28 insertions(+), 33 deletions(-) (limited to 'libglusterfs') 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 @@ -143,9 +143,6 @@ inode_rename (inode_table_t *table, inode_t *olddir, const char *oldname, 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); -- cgit