From 753146c0ff4b1b55892b71b36d6ca97797867aaa Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Tue, 27 Jul 2010 11:13:32 +0000 Subject: some check added to the variables after GF_CALLOC handles some NULL dereference problems (reported by clang when ran with code where '#define GF_CALLOC NULL'). Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 966 (NULL check for avoiding NULL dereferencing of pointers..) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=966 --- libglusterfs/src/common-utils.c | 2 ++ libglusterfs/src/event.c | 5 +++++ libglusterfs/src/logging.c | 5 +++++ libglusterfs/src/xlator.c | 3 +++ 4 files changed, 15 insertions(+) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 1be1f81268b..1077f610011 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -90,6 +90,8 @@ gf_resolve_ip6 (const char *hostname, if (!*dnscache) { *dnscache = GF_CALLOC (1, sizeof (struct dnscache6), gf_common_mt_dnscache6); + if (!*dnscache) + return -1; } cache = *dnscache; diff --git a/libglusterfs/src/event.c b/libglusterfs/src/event.c index 3243e7f2320..59b1bd79eac 100644 --- a/libglusterfs/src/event.c +++ b/libglusterfs/src/event.c @@ -195,6 +195,8 @@ event_register_poll (struct event_pool *event_pool, int fd, event_pool->reg = GF_REALLOC (event_pool->reg, event_pool->count * sizeof (*event_pool->reg)); + if (!event_pool->reg) + goto unlock; } idx = event_pool->used++; @@ -239,6 +241,7 @@ event_register_poll (struct event_pool *event_pool, int fd, event_pool->changed = 1; } +unlock: pthread_mutex_unlock (&event_pool->mutex); return idx; @@ -402,6 +405,8 @@ event_dispatch_poll_resize (struct event_pool *event_pool, ufds = GF_CALLOC (sizeof (struct pollfd), event_pool->evcache_size, gf_common_mt_pollfd); + if (!ufds) + goto unlock; event_pool->evcache = ufds; } diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index d5a38e6b6b8..000c2ccd34f 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -311,6 +311,9 @@ __logfile_for_client (char *identifier) if (!client_logs) { client = GF_CALLOC (1, sizeof (*client), gf_common_mt_client_log); + if (!client) + return NULL; + client_log_init (client, identifier); client_logs = client; @@ -324,6 +327,8 @@ __logfile_for_client (char *identifier) if (!client) { client = GF_CALLOC (1, sizeof (*client), gf_common_mt_client_log); + if (!client) + return NULL; client_log_init (client, identifier); diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index c2f585d03a0..e5b97f7c4a5 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -749,6 +749,9 @@ xlator_set_type (xlator_t *xl, vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t); + if (!vol_opt) + return -1; + if (!(vol_opt->given_opt = dlsym (handle, "options"))) { dlerror (); gf_log (xl->name, GF_LOG_DEBUG, -- cgit