summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2009-12-24 12:10:09 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-01-08 10:22:12 -0800
commit2674d226f41bf090c8f69c676f22102f877a75c5 (patch)
treea7e75bcbcfa39c00a7669da659a9d40184fdecda /libglusterfs
parent3adb7082c63d28950aca21718be84b65806e5d6e (diff)
libglusterfs/inode: add NULL checks.
Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 510 (crash in inode_ref) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=510
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/inode.c45
1 files changed, 37 insertions, 8 deletions
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;
}