From 2674d226f41bf090c8f69c676f22102f877a75c5 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Thu, 24 Dec 2009 12:10:09 +0000 Subject: libglusterfs/inode: add NULL checks. Signed-off-by: Raghavendra G Signed-off-by: Anand V. Avati BUG: 510 (crash in inode_ref) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=510 --- libglusterfs/src/inode.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'libglusterfs') diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index 5b70ce5fe..f4561cc27 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -425,17 +425,29 @@ __dentry_create (inode_t *inode, inode_t *parent, const char *name) dentry_t *newd = NULL; newd = (void *) CALLOC (1, sizeof (*newd)); + if (newd == NULL) { + gf_log ("inode", GF_LOG_ERROR, "out of memory"); + goto out; + } INIT_LIST_HEAD (&newd->inode_list); INIT_LIST_HEAD (&newd->hash); + newd->name = strdup (name); + if (newd->name == NULL) { + gf_log ("inode", GF_LOG_ERROR, "out of memory"); + FREE (newd); + newd = NULL; + goto out; + } + if (parent) newd->parent = __inode_ref (parent); - newd->name = strdup (name); list_add (&newd->inode_list, &inode->dentry_list); newd->inode = inode; +out: return newd; } @@ -446,8 +458,10 @@ __inode_create (inode_table_t *table) inode_t *newi = NULL; newi = (void *) CALLOC (1, sizeof (*newi)); - if (!newi) - return NULL; + if (!newi) { + gf_log ("inode", GF_LOG_ERROR, "out of memory"); + goto out; + } newi->table = table; @@ -458,13 +472,20 @@ __inode_create (inode_table_t *table) INIT_LIST_HEAD (&newi->hash); INIT_LIST_HEAD (&newi->dentry_list); + newi->_ctx = CALLOC (1, (sizeof (struct _inode_ctx) * + table->xl->ctx->xl_count)); + if (newi->_ctx == NULL) { + gf_log ("inode", GF_LOG_ERROR, "out of memory"); + LOCK_DESTROY (&newi->lock); + FREE (newi); + newi = NULL; + goto out; + } list_add (&newi->list, &table->lru); table->lru_size++; - newi->_ctx = CALLOC (1, (sizeof (struct _inode_ctx) * - table->xl->ctx->xl_count)); - +out: return newi; } @@ -477,7 +498,9 @@ inode_new (inode_table_t *table) pthread_mutex_lock (&table->lock); { inode = __inode_create (table); - __inode_ref (inode); + if (inode != NULL) { + __inode_ref (inode); + } } pthread_mutex_unlock (&table->lock); @@ -1080,9 +1103,14 @@ inode_from_path (inode_table_t *itable, const char *path) char *strtokptr = NULL; /* top-down approach */ + pathname = strdup (path); + if (pathname == NULL) { + gf_log ("inode", GF_LOG_ERROR, "out of memory"); + goto out; + } + root = itable->root; parent = inode_ref (root); - pathname = strdup (path); component = strtok_r (pathname, "/", &strtokptr); if (component == NULL) @@ -1116,6 +1144,7 @@ inode_from_path (inode_table_t *itable, const char *path) if (pathname) free (pathname); +out: return inode; } -- cgit