diff options
Diffstat (limited to 'libglusterfs/src')
-rw-r--r-- | libglusterfs/src/call-stub.c | 8 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 5 | ||||
-rw-r--r-- | libglusterfs/src/dict.c | 35 | ||||
-rw-r--r-- | libglusterfs/src/fd.c | 29 | ||||
-rw-r--r-- | libglusterfs/src/stack.h | 10 | ||||
-rw-r--r-- | libglusterfs/src/timer.c | 15 |
6 files changed, 69 insertions, 33 deletions
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c index 233a1616250..497637fa9dc 100644 --- a/libglusterfs/src/call-stub.c +++ b/libglusterfs/src/call-stub.c @@ -1738,7 +1738,8 @@ fop_readdirp_cbk_stub (call_frame_t *frame, if (op_ret > 0) { list_for_each_entry (entry, &entries->list, list) { stub_entry = gf_dirent_for_name (entry->d_name); - ERR_ABORT (stub_entry); + if (!stub_entry) + goto out; stub_entry->d_off = entry->d_off; stub_entry->d_ino = entry->d_ino; stub_entry->d_stat = entry->d_stat; @@ -1780,11 +1781,12 @@ fop_readdir_cbk_stub (call_frame_t *frame, if (op_ret > 0) { list_for_each_entry (entry, &entries->list, list) { stub_entry = gf_dirent_for_name (entry->d_name); - ERR_ABORT (stub_entry); + if (!stub_entry) + goto out; stub_entry->d_off = entry->d_off; stub_entry->d_ino = entry->d_ino; - list_add_tail (&stub_entry->list, + list_add_tail (&stub_entry->list, &stub->args.readdir_cbk.entries.list); } } diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index b11e3043f1f..ab230993a5c 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -68,11 +68,6 @@ void trap (void); #define GF_UNIT_PB_STRING "PB" -#define ERR_ABORT(ptr) \ - if (ptr == NULL) { \ - abort (); \ - } - enum _gf_boolean { _gf_false = 0, diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 1f60116238f..4a8945ff136 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -40,11 +40,12 @@ data_pair_t * get_new_data_pair () { data_pair_t *data_pair_ptr = NULL; - + data_pair_ptr = (data_pair_t *) GF_CALLOC (1, sizeof (data_pair_t), gf_common_mt_data_pair_t); - ERR_ABORT (data_pair_ptr); - + if (!data_pair_ptr) + gf_log ("dict", GF_LOG_ERROR, "memory alloc failed"); + return data_pair_ptr; } @@ -1064,7 +1065,9 @@ data_to_int64 (data_t *data) return -1; char *str = alloca (data->len + 1); - ERR_ABORT (str); + if (!str) + return -1; + memcpy (str, data->data, data->len); str[data->len] = '\0'; return (int64_t) strtoull (str, NULL, 0); @@ -1077,7 +1080,9 @@ data_to_int32 (data_t *data) return -1; char *str = alloca (data->len + 1); - ERR_ABORT (str); + if (!str) + return -1; + memcpy (str, data->data, data->len); str[data->len] = '\0'; @@ -1091,7 +1096,9 @@ data_to_int16 (data_t *data) return -1; char *str = alloca (data->len + 1); - ERR_ABORT (str); + if (!str) + return -1; + memcpy (str, data->data, data->len); str[data->len] = '\0'; @@ -1106,7 +1113,9 @@ data_to_int8 (data_t *data) return -1; char *str = alloca (data->len + 1); - ERR_ABORT (str); + if (!str) + return -1; + memcpy (str, data->data, data->len); str[data->len] = '\0'; @@ -1120,7 +1129,9 @@ data_to_uint64 (data_t *data) if (!data) return -1; char *str = alloca (data->len + 1); - ERR_ABORT (str); + if (!str) + return -1; + memcpy (str, data->data, data->len); str[data->len] = '\0'; @@ -1134,7 +1145,9 @@ data_to_uint32 (data_t *data) return -1; char *str = alloca (data->len + 1); - ERR_ABORT (str); + if (!str) + return -1; + memcpy (str, data->data, data->len); str[data->len] = '\0'; @@ -1148,7 +1161,9 @@ data_to_uint16 (data_t *data) return -1; char *str = alloca (data->len + 1); - ERR_ABORT (str); + if (!str) + return -1; + memcpy (str, data->data, data->len); str[data->len] = '\0'; diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index d26854ebdfb..9269e5cf838 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -87,10 +87,12 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr) { fdentry_t *oldfds = NULL; uint32_t oldmax_fds = -1; + int ret = -1; if (fdtable == NULL || nr < 0) { gf_log ("fd", GF_LOG_ERROR, "invalid argument"); - return EINVAL; + ret = EINVAL; + goto out; } nr /= (1024 / sizeof (fdentry_t)); @@ -102,7 +104,10 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr) fdtable->fdentries = GF_CALLOC (nr, sizeof (fdentry_t), gf_common_mt_fdentry_t); - ERR_ABORT (fdtable->fdentries); + if (!fdtable->fdentries) { + ret = ENOMEM; + goto out; + } fdtable->max_fds = nr; if (oldfds) { @@ -119,7 +124,9 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr) */ fdtable->first_free = oldmax_fds; GF_FREE (oldfds); - return 0; + ret = 0; +out: + return ret; } @@ -499,11 +506,17 @@ fd_create (inode_t *inode, pid_t pid) } fd = GF_CALLOC (1, sizeof (fd_t), gf_common_mt_fd_t); - ERR_ABORT (fd); + if (!fd) + goto out; - fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) * + fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) * inode->table->xl->graph->xl_count), gf_common_mt_fd_ctx); + if (!fd->_ctx) { + GF_FREE (fd); + fd = NULL; + goto out; + } fd->inode = inode_ref (inode); fd->pid = pid; @@ -512,9 +525,11 @@ fd_create (inode_t *inode, pid_t pid) LOCK_INIT (&fd->lock); LOCK (&inode->lock); - fd = _fd_ref (fd); + { + fd = _fd_ref (fd); + } UNLOCK (&inode->lock); - +out: return fd; } diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h index 1ce46ccdc89..6015b8158b0 100644 --- a/libglusterfs/src/stack.h +++ b/libglusterfs/src/stack.h @@ -184,7 +184,10 @@ STACK_DESTROY (call_stack_t *stack) \ _new = GF_CALLOC (1, sizeof (call_frame_t), \ gf_common_mt_call_frame_t); \ - ERR_ABORT (_new); \ + if (!_new) { \ + gf_log ("stack", GF_LOG_ERROR, "alloc failed"); \ + break; \ + } \ typeof(fn##_cbk) tmp_cbk = rfn; \ _new->root = frame->root; \ _new->next = frame->root->frames.next; \ @@ -219,7 +222,10 @@ STACK_DESTROY (call_stack_t *stack) \ _new = GF_CALLOC (1, sizeof (call_frame_t), \ gf_common_mt_call_frame_t); \ - ERR_ABORT (_new); \ + if (!_new) { \ + gf_log ("stack", GF_LOG_ERROR, "alloc failed"); \ + break; \ + } \ typeof(fn##_cbk) tmp_cbk = rfn; \ _new->root = frame->root; \ _new->next = frame->root->frames.next; \ diff --git a/libglusterfs/src/timer.c b/libglusterfs/src/timer.c index 7ff18f94e35..3e39231e0b7 100644 --- a/libglusterfs/src/timer.c +++ b/libglusterfs/src/timer.c @@ -201,18 +201,19 @@ gf_timer_proc (void *ctx) gf_timer_registry_t * gf_timer_registry_init (glusterfs_ctx_t *ctx) { - if (ctx == NULL) - { + if (ctx == NULL) { gf_log ("timer", GF_LOG_ERROR, "invalid argument"); return NULL; } - + if (!ctx->timer) { gf_timer_registry_t *reg = NULL; - ctx->timer = reg = GF_CALLOC (1, sizeof (*reg), - gf_common_mt_gf_timer_registry_t); - ERR_ABORT (reg); + reg = GF_CALLOC (1, sizeof (*reg), + gf_common_mt_gf_timer_registry_t); + if (!reg) + goto out; + pthread_mutex_init (®->lock, NULL); reg->active.next = ®->active; reg->active.prev = ®->active; @@ -220,6 +221,8 @@ gf_timer_registry_init (glusterfs_ctx_t *ctx) reg->stale.prev = ®->stale; pthread_create (®->th, NULL, gf_timer_proc, ctx); + ctx->timer = reg; } +out: return ctx->timer; } |