From 29f2de478cc6a475e6ae760d9cbe7ac847e9d79c Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Fri, 13 Apr 2012 17:29:41 +0530 Subject: core: coverity issues fixed this is not a complete set of issues getting fixed. Will address other issues in another patch. Change-Id: Ib01c7b11b205078cc4d0b3f11610751e32d14b69 Signed-off-by: Amar Tumballi BUG: 789278 Reviewed-on: http://review.gluster.com/3145 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy --- cli/src/cli-cmd-volume.c | 2 +- libglusterfs/src/dict.c | 268 +----------------------- libglusterfs/src/dict.h | 4 - libglusterfs/src/options.c | 5 +- rpc/rpc-lib/src/rpcsvc.c | 4 +- xlators/cluster/dht/src/dht-layout.c | 3 + xlators/cluster/dht/src/dht-selfheal.c | 3 + xlators/cluster/stripe/src/stripe-helpers.c | 6 +- xlators/cluster/stripe/src/stripe.c | 2 +- xlators/debug/trace/src/trace.c | 3 + xlators/features/index/src/index.c | 3 + xlators/features/quota/src/quota.c | 3 + xlators/lib/src/libxlator.c | 3 +- xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 14 +- xlators/mgmt/glusterd/src/glusterd-handler.c | 4 +- xlators/mgmt/glusterd/src/glusterd-handshake.c | 4 +- xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 28 ++- xlators/mgmt/glusterd/src/glusterd-store.c | 9 +- xlators/mgmt/glusterd/src/glusterd-utils.c | 2 +- xlators/mgmt/glusterd/src/glusterd-volgen.c | 2 +- xlators/mgmt/glusterd/src/glusterd.c | 9 +- xlators/mount/fuse/src/fuse-bridge.c | 6 +- xlators/mount/fuse/src/fuse-helpers.c | 4 + xlators/performance/io-threads/src/io-threads.c | 10 +- xlators/protocol/client/src/client-handshake.c | 3 +- xlators/protocol/server/src/authenticate.c | 20 +- xlators/storage/posix/src/posix.c | 47 ++--- 27 files changed, 135 insertions(+), 336 deletions(-) diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 3f76b6150da..ea7a13761e3 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1588,7 +1588,7 @@ cli_print_brick_status (cli_volume_status_t *status) while (bricklen > 0) { if (bricklen > fieldlen) { i++; - strncpy (buf, p, fieldlen); + strncpy (buf, p, min (fieldlen, (sizeof (buf)-1))); buf[strlen(buf) + 1] = '\0'; cli_out ("%s", buf); p = status->brick + i * fieldlen; diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index ed89f236a30..a2b1ec0a256 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -143,8 +143,6 @@ data_destroy (data_t *data) else GF_FREE (data->data); } - if (data->vec) - GF_FREE (data->vec); } data->len = 0xbabababa; @@ -174,12 +172,6 @@ data_copy (data_t *old) if (!newdata->data) goto err_out; } - if (old->vec) { - newdata->vec = memdup (old->vec, old->len * (sizeof (void *) + - sizeof (size_t))); - if (!newdata->vec) - goto err_out; - } } LOCK_INIT (&newdata->lock); @@ -189,8 +181,6 @@ err_out: if (newdata->data) FREE (newdata->data); - if (newdata->vec) - FREE (newdata->vec); mem_put (newdata); return NULL; @@ -506,236 +496,6 @@ data_ref (data_t *this) return this; } -/* - Serialization format: - ---- - Count:8 - Key_len:8:Value_len:8 - Key - Value - . - . - . -*/ - -int32_t -dict_serialized_length_old (dict_t *this) -{ - - if (!this) { - gf_log_callingfn ("dict", GF_LOG_WARNING, "dict is NULL"); - return -1; - } - - int32_t len = 9; /* count + \n */ - int32_t count = this->count; - data_pair_t *pair = this->members_list; - - while (count) { - len += 18; - len += strlen (pair->key) + 1; - if (pair->value->vec) { - int i; - for (i=0; ivalue->len; i++) { - len += pair->value->vec[i].iov_len; - } - } else { - len += pair->value->len; - } - pair = pair->next; - count--; - } - - return len; -} - -int32_t -dict_serialize_old (dict_t *this, char *buf) -{ - if (!this || !buf) { - gf_log_callingfn ("dict", GF_LOG_WARNING, "dict is NULL"); - return -1; - } - - data_pair_t *pair = this->members_list; - int32_t count = this->count; - uint64_t dcount = this->count; - - // FIXME: magic numbers - - sprintf (buf, "%08"PRIx64"\n", dcount); - buf += 9; - while (count) { - uint64_t keylen = strlen (pair->key) + 1; - uint64_t vallen = pair->value->len; - - sprintf (buf, "%08"PRIx64":%08"PRIx64"\n", keylen, vallen); - buf += 18; - memcpy (buf, pair->key, keylen); - buf += keylen; - memcpy (buf, pair->value->data, pair->value->len); - buf += pair->value->len; - pair = pair->next; - count--; - } - return (0); -} - - -dict_t * -dict_unserialize_old (char *buf, int32_t size, dict_t **fill) -{ - int32_t ret = 0; - int32_t cnt = 0; - - if (!buf || !fill || !(*fill)) { - gf_log_callingfn ("dict", GF_LOG_WARNING, "buf is NULL"); - return NULL; - } - - uint64_t count; - ret = sscanf (buf, "%"SCNx64"\n", &count); - (*fill)->count = 0; - - if (!ret){ - gf_log ("dict", GF_LOG_ERROR, "sscanf on buf failed"); - goto err; - } - buf += 9; - - if (count == 0) { - gf_log ("dict", GF_LOG_ERROR, "count == 0"); - goto err; - } - - for (cnt = 0; cnt < count; cnt++) { - data_t *value = NULL; - char *key = NULL; - uint64_t key_len, value_len; - - ret = sscanf (buf, "%"SCNx64":%"SCNx64"\n", &key_len, &value_len); - if (ret != 2) { - gf_log ("dict", GF_LOG_ERROR, - "sscanf for key_len and value_len failed"); - goto err; - } - buf += 18; - - key = buf; - buf += key_len; - - value = get_new_data (); - value->len = value_len; - value->data = buf; - value->is_static = 1; - buf += value_len; - - dict_set (*fill, key, value); - } - - goto ret; - -err: - GF_FREE (*fill); - *fill = NULL; - -ret: - return *fill; -} - - -int32_t -dict_iovec_len (dict_t *this) -{ - if (!this) { - gf_log_callingfn ("dict", GF_LOG_WARNING, "dict is NULL"); - return -1; - } - - int32_t len = 0; - data_pair_t *pair = this->members_list; - - len++; /* initial header */ - while (pair) { - len++; /* pair header */ - len++; /* key */ - - if (pair->value->vec) - len += pair->value->len; - else - len++; - pair = pair->next; - } - - return len; -} - -int32_t -dict_to_iovec (dict_t *this, - struct iovec *vec, - int32_t count) -{ - if (!this || !vec) { - gf_log_callingfn ("dict", GF_LOG_WARNING, "dict is NULL"); - return -1; - } - - int32_t i = 0; - data_pair_t *pair = this->members_list; - - vec[0].iov_len = 9; - if (vec[0].iov_base) - sprintf (vec[0].iov_base, - "%08"PRIx64"\n", - (int64_t)this->count); - i++; - - while (pair) { - int64_t keylen = strlen (pair->key) + 1; - int64_t vallen = 0; - - if (pair->value->vec) { - int i; - - for (i=0; ivalue->len; i++) { - vallen += pair->value->vec[i].iov_len; - } - } else { - vallen = pair->value->len; - } - - vec[i].iov_len = 18; - if (vec[i].iov_base) - sprintf (vec[i].iov_base, - "%08"PRIx64":%08"PRIx64"\n", - keylen, - vallen); - i++; - - vec[i].iov_len = keylen; - vec[i].iov_base = pair->key; - i++; - - if (pair->value->vec) { - int k; - - for (k=0; kvalue->len; k++) { - vec[i].iov_len = pair->value->vec[k].iov_len; - vec[i].iov_base = pair->value->vec[k].iov_base; - i++; - } - } else { - vec[i].iov_len = pair->value->len; - vec[i].iov_base = pair->value->data; - i++; - } - - pair = pair->next; - } - - return 0; -} - data_t * int_to_data (int64_t value) { @@ -2354,7 +2114,6 @@ _dict_serialized_length (dict_t *this) int ret = -EINVAL; int count = 0; int len = 0; - int i = 0; data_pair_t * pair = NULL; len = DICT_HDR_LEN; @@ -2389,28 +2148,15 @@ _dict_serialized_length (dict_t *this) goto out; } - if (pair->value->vec) { - for (i = 0; i < pair->value->len; i++) { - if (pair->value->vec[i].iov_len < 0) { - gf_log ("dict", GF_LOG_ERROR, - "iov_len (%"GF_PRI_SIZET") < 0!", - pair->value->vec[i].iov_len); - goto out; - } - - len += pair->value->vec[i].iov_len; - } - } else { - if (pair->value->len < 0) { - gf_log ("dict", GF_LOG_ERROR, - "value->len (%d) < 0", - pair->value->len); - goto out; - } - - len += pair->value->len; + if (pair->value->len < 0) { + gf_log ("dict", GF_LOG_ERROR, + "value->len (%d) < 0", + pair->value->len); + goto out; } + len += pair->value->len; + pair = pair->next; count--; } diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index 68579ad7b4f..a3f4013a0e2 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -85,7 +85,6 @@ struct _data { unsigned char is_const:1; unsigned char is_stdalloc:1; int32_t len; - struct iovec *vec; char *data; int32_t refcount; gf_lock_t lock; @@ -126,9 +125,6 @@ int32_t dict_unserialize (char *buf, int32_t size, dict_t **fill); int32_t dict_allocate_and_serialize (dict_t *this, char **buf, size_t *length); -int32_t dict_iovec_len (dict_t *dict); -int32_t dict_to_iovec (dict_t *dict, struct iovec *vec, int32_t count); - void dict_destroy (dict_t *dict); void dict_unref (dict_t *dict); dict_t *dict_ref (dict_t *dict); diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index 762f15f99b1..0aa942e209c 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -252,7 +252,8 @@ xlator_option_validate_str (xlator_t *xl, const char *key, const char *value, #endif } - if ((i <= ZR_OPTION_MAX_ARRAY_SIZE) && (!opt->value[i])) { + if (((i < ZR_OPTION_MAX_ARRAY_SIZE) && (!opt->value[i])) || + (i == ZR_OPTION_MAX_ARRAY_SIZE)) { /* enter here only if * 1. reached end of opt->value array and haven't * validated input @@ -720,7 +721,7 @@ xlator_volume_option_get_list (volume_opt_list_t *vol_list, const char *key) } else opt = vol_list->given_opt; - for (index = 0; opt[index].key && opt[index].key[0]; index++) { + for (index = 0; opt[index].key[0]; index++) { for (i = 0; i < ZR_VOLUME_MAX_NUM_KEY; i++) { cmp_key = opt[index].key[i]; if (!cmp_key) diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index a4f74d8b5ae..b64c43f0e75 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.c @@ -313,7 +313,9 @@ rpcsvc_request_init (rpcsvc_t *svc, rpc_transport_t *trans, req->msg[0] = progmsg; req->iobref = iobref_ref (msg->iobref); if (msg->vectored) { - for (i = 1; i < msg->count; i++) { + /* msg->vector[2] is defined in structure. prevent a + out of bound access */ + for (i = 1; i < min (msg->count, 2); i++) { req->msg[i] = msg->vector[i]; } } diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c index d1f8c9fbb0d..3c583c7bde8 100644 --- a/xlators/cluster/dht/src/dht-layout.c +++ b/xlators/cluster/dht/src/dht-layout.c @@ -280,6 +280,9 @@ dht_disk_layout_extract (xlator_t *this, dht_layout_t *layout, if (disk_layout_p) *disk_layout_p = disk_layout; + else + GF_FREE (disk_layout); + ret = 0; out: diff --git a/xlators/cluster/dht/src/dht-selfheal.c b/xlators/cluster/dht/src/dht-selfheal.c index 420af4b7f93..9c8aeac2586 100644 --- a/xlators/cluster/dht/src/dht-selfheal.c +++ b/xlators/cluster/dht/src/dht-selfheal.c @@ -706,6 +706,9 @@ done: local->layout = new_layout; } + if (fix_array) + GF_FREE (fix_array); + return new_layout; } diff --git a/xlators/cluster/stripe/src/stripe-helpers.c b/xlators/cluster/stripe/src/stripe-helpers.c index ed7ed1a0b79..dcd2022f7f2 100644 --- a/xlators/cluster/stripe/src/stripe-helpers.c +++ b/xlators/cluster/stripe/src/stripe-helpers.c @@ -440,7 +440,6 @@ set_stripe_block_size (xlator_t *this, stripe_private_t *priv, char *data) stripe_opt = GF_CALLOC (1, sizeof (struct stripe_options), gf_stripe_mt_stripe_options); if (!stripe_opt) { - GF_FREE (dup_str); goto out; } @@ -486,10 +485,15 @@ set_stripe_block_size (xlator_t *this, stripe_private_t *priv, char *data) stripe_str = strtok_r (NULL, ",", &tmp_str); GF_FREE (dup_str); + dup_str = NULL; } ret = 0; out: + + if (dup_str) + GF_FREE (dup_str); + return ret; } diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c index 86cc66f59c1..627e17dca77 100644 --- a/xlators/cluster/stripe/src/stripe.c +++ b/xlators/cluster/stripe/src/stripe.c @@ -4470,7 +4470,7 @@ stripe_vgetxattr_cbk (call_frame_t *frame, void *cookie, local = frame->local; cky = (long) cookie; - if (!local->xsel) { + if (local->xsel[0] == '\0') { gf_log (this->name, GF_LOG_ERROR, "Empty xattr in cbk"); return ret; } diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c index aada90d3824..d9c292c0104 100644 --- a/xlators/debug/trace/src/trace.c +++ b/xlators/debug/trace/src/trace.c @@ -473,6 +473,9 @@ trace_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, preoldparentstr, postoldparentstr, prenewparentstr, postnewparentstr); + if (statstr) + GF_FREE (statstr); + if (preoldparentstr) GF_FREE (preoldparentstr); diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c index ead20e06f88..8f630f2f94e 100644 --- a/xlators/features/index/src/index.c +++ b/xlators/features/index/src/index.c @@ -1079,6 +1079,9 @@ init (xlator_t *this) } ret = 0; out: + if (!this->private && priv) + GF_FREE (priv); + return ret; } diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index f6c4e0099b9..436fb1b1cb1 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -497,6 +497,9 @@ quota_get_limit_value (inode_t *inode, xlator_t *this, int64_t *n) } out: + if (path) + GF_FREE (path); + return ret; } diff --git a/xlators/lib/src/libxlator.c b/xlators/lib/src/libxlator.c index fe11e35b56d..195bd523663 100644 --- a/xlators/lib/src/libxlator.c +++ b/xlators/lib/src/libxlator.c @@ -187,12 +187,13 @@ out: frame->local = local->xl_local; local->xl_specf_unwind (frame, op_ret, op_errno, dict, xdata); - return 0; } else if (need_unwind) { STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata); } + if (marker_xattr) + GF_FREE (marker_xattr); return 0; } diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index 4dc9396668d..c373fc14f1f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -524,7 +524,7 @@ gsync_status (char *master, char *slave, int *status) int fd = -1; fd = gsyncd_getpidfile (master, slave, pidfile); - if (fd == -2) + if ((fd == -2) || (fd == -1)) return -1; *status = gsync_status_byfd (fd); @@ -1118,7 +1118,7 @@ stop_gsync (char *master, char *slave, char **msg) GF_ASSERT (THIS->private); pfd = gsyncd_getpidfile (master, slave, pidfile); - if (pfd == -2) { + if ((pfd == -2) || (pfd == -1)) { gf_log ("", GF_LOG_ERROR, GEOREP" stop validation " " failed for %s & %s", master, slave); ret = -1; @@ -1160,7 +1160,8 @@ stop_gsync (char *master, char *slave, char **msg) ret = 0; out: - close (pfd); + if ((pfd != -2) && (pfd != -1)) + close (pfd); return ret; } @@ -1652,7 +1653,7 @@ glusterd_get_pid_from_file (char *master, char *slave, pid_t *pid) pfd = gsyncd_getpidfile (master, slave, pidfile); - if (pfd == -2) { + if ((pfd == -2) || (pfd == -1)) { gf_log ("", GF_LOG_ERROR, GEOREP" log-rotate validation " " failed for %s & %s", master, slave); goto out; @@ -1669,12 +1670,13 @@ glusterd_get_pid_from_file (char *master, char *slave, pid_t *pid) goto out; } - close(pfd); *pid = strtol (buff, NULL, 10); ret = 0; - out: +out: + if ((pfd != -2) && (pfd != -1)) + close(pfd); return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 6ea40bc4d6c..d7ac4fd4f2c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -83,8 +83,10 @@ glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid, if (ret) { ret = glusterd_xfer_friend_add_resp (req, rhost, port, -1, GF_PROBE_UNKNOWN_PEER); - if (friend_req->vols.vols_val) + if (friend_req->vols.vols_val) { free (friend_req->vols.vols_val); + friend_req->vols.vols_val = NULL; + } goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index 64945a716c4..d80cacc8afd 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -209,13 +209,13 @@ fail: rsp.op_errno = cookie; if (!rsp.spec) - rsp.spec = ""; + rsp.spec = strdup (""); glusterd_submit_reply (req, &rsp, NULL, 0, NULL, (xdrproc_t)xdr_gf_getspec_rsp); if (args.key) free (args.key);//malloced by xdr - if (rsp.spec && (strcmp (rsp.spec, ""))) + if (rsp.spec) free (rsp.spec); return 0; diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index ddc4d1f492d..a7ccda71f72 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -837,7 +837,9 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov, if (-1 == req->rpc_status) { rsp.op_ret = -1; rsp.op_errno = EINVAL; - rsp.op_errstr = "error"; + /* use standard allocation because to keep uniformity + in freeing it */ + rsp.op_errstr = strdup ("error"); goto out; } @@ -846,7 +848,9 @@ glusterd3_1_stage_op_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("", GF_LOG_ERROR, "error"); rsp.op_ret = -1; rsp.op_errno = EINVAL; - rsp.op_errstr = "error"; + /* use standard allocation because to keep uniformity + in freeing it */ + rsp.op_errstr = strdup ("xdr decoding failed"); goto out; } @@ -918,7 +922,7 @@ out: glusterd_op_sm (); } - if (rsp.op_errstr && strcmp (rsp.op_errstr, "error")) + if (rsp.op_errstr) free (rsp.op_errstr); //malloced by xdr if (dict) { if (!dict->extra_stdfree && rsp.dict.dict_val) @@ -1268,17 +1272,21 @@ glusterd3_1_commit_op_cbk (struct rpc_req *req, struct iovec *iov, if (-1 == req->rpc_status) { rsp.op_ret = -1; rsp.op_errno = EINVAL; - rsp.op_errstr = "error"; + /* use standard allocation because to keep uniformity + in freeing it */ + rsp.op_errstr = strdup ("error"); event_type = GD_OP_EVENT_RCVD_RJT; goto out; } ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gd1_mgmt_commit_op_rsp); if (ret < 0) { - gf_log ("", GF_LOG_ERROR, "error"); + gf_log ("", GF_LOG_ERROR, "xdr decoding error"); rsp.op_ret = -1; rsp.op_errno = EINVAL; - rsp.op_errstr = "error"; + /* use standard allocation because to keep uniformity + in freeing it */ + rsp.op_errstr = strdup ("xdr decoding error"); event_type = GD_OP_EVENT_RCVD_RJT; goto out; } @@ -1395,7 +1403,7 @@ out: if (dict) dict_unref (dict); - if (rsp.op_errstr && strcmp (rsp.op_errstr, "error")) + if (rsp.op_errstr) free (rsp.op_errstr); //malloced by xdr GLUSTERD_STACK_DESTROY (((call_frame_t *)myframe)); return ret; @@ -1788,7 +1796,9 @@ glusterd3_1_brick_op_cbk (struct rpc_req *req, struct iovec *iov, if (-1 == req->rpc_status) { rsp.op_ret = -1; rsp.op_errno = EINVAL; - rsp.op_errstr = "error"; + /* use standard allocation because to keep uniformity + in freeing it */ + rsp.op_errstr = strdup ("error"); event_type = GD_OP_EVENT_RCVD_RJT; goto out; } @@ -1857,7 +1867,7 @@ out: if (ret && dict) dict_unref (dict); - if (rsp.op_errstr && strcmp (rsp.op_errstr, "error")) + if (rsp.op_errstr) free (rsp.op_errstr); //malloced by xdr GLUSTERD_STACK_DESTROY (frame); return ret; diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 56c1d98754a..076520bf936 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -1077,12 +1077,17 @@ glusterd_store_retrieve_value (glusterd_store_handle_t *handle, handle->fd = open (handle->path, O_RDWR); + if (handle->fd == -1) { + gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s", + handle->path, strerror (errno)); + goto out; + } if (!handle->read) handle->read = fdopen (handle->fd, "r"); if (!handle->read) { - gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %d", - handle->path, errno); + gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %s", + handle->path, strerror (errno)); goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 1eaed4e383c..ed7ba1d51e6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -300,7 +300,7 @@ glusterd_unlock (uuid_t uuid) glusterd_get_lock_owner (&owner); - if (NULL == owner) { + if (uuid_is_null (owner)) { gf_log ("glusterd", GF_LOG_ERROR, "Cluster lock not held!"); goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index dea139ebc2b..f7d17f00d0e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -2569,7 +2569,7 @@ nfs_option_handler (volgen_graph_t *graph, ret = xlator_set_option (xl, vme->key, vme->value); }*/ - if ( !volinfo || !volinfo->volname) + if (!volinfo || (volinfo->volname[0] == '\0')) return 0; if (! strcmp (vme->option, "!rpc-auth.addr.*.allow")) { diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index 7f41721c0a2..6acf3daffce 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -650,9 +650,12 @@ check_prepare_mountbroker_root (char *mountbroker_root) ret = 0; out: - close (dfd0); - close (dfd); - close (dfd2); + if (dfd0 != -1) + close (dfd0); + if (dfd != -1) + close (dfd); + if (dfd2 != -1) + close (dfd2); return ret; } diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index c06da7eec58..9a2d60b9b4c 100644 --- a/xlators/mount/fuse/src/fuse-bridge.c +++ b/xlators/mount/fuse/src/fuse-bridge.c @@ -4601,8 +4601,10 @@ cleanup_exit: GF_FREE (fsname); if (priv) { GF_FREE (priv->mount_point); - close (priv->fd); - close (priv->fuse_dump_fd); + if (priv->fd != -1) + close (priv->fd); + if (priv->fuse_dump_fd != -1) + close (priv->fuse_dump_fd); GF_FREE (priv); } if (mnt_args) diff --git a/xlators/mount/fuse/src/fuse-helpers.c b/xlators/mount/fuse/src/fuse-helpers.c index 452a4819441..fbff1e39a0c 100644 --- a/xlators/mount/fuse/src/fuse-helpers.c +++ b/xlators/mount/fuse/src/fuse-helpers.c @@ -392,6 +392,10 @@ fuse_loc_fill (loc_t *loc, fuse_state_t *state, ino_t ino, } ret = 0; fail: + /* this should not happen as inode_path returns -1 when buf is NULL + for sure */ + if (path && !loc->path) + GF_FREE (path); return ret; } diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index 66864fcd438..04abac7ad31 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -2489,9 +2489,9 @@ out: int init (xlator_t *this) { - iot_conf_t *conf = NULL; - int ret = -1; - int i = 0; + iot_conf_t *conf = NULL; + int ret = -1; + int i = 0; if (!this->children || this->children->next) { gf_log ("io-threads", GF_LOG_ERROR, @@ -2553,13 +2553,15 @@ init (xlator_t *this) if (ret == -1) { gf_log (this->name, GF_LOG_ERROR, "cannot initialize worker threads, exiting init"); - GF_FREE (conf); goto out; } this->private = conf; ret = 0; out: + if (ret) + GF_FREE (conf); + return ret; } diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c index 944b9ca80b2..a3cb325b02a 100644 --- a/xlators/protocol/client/src/client-handshake.c +++ b/xlators/protocol/client/src/client-handshake.c @@ -1369,8 +1369,7 @@ client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *m remote_error ? remote_error : strerror (op_errno)); errno = op_errno; if (remote_error && - (strncmp ("Authentication failed",remote_error, - sizeof (remote_error)) == 0)) { + (strcmp ("Authentication failed", remote_error) == 0)) { auth_fail = _gf_true; op_ret = 0; } diff --git a/xlators/protocol/server/src/authenticate.c b/xlators/protocol/server/src/authenticate.c index de5bf9f437b..ffadf2e4d67 100644 --- a/xlators/protocol/server/src/authenticate.c +++ b/xlators/protocol/server/src/authenticate.c @@ -34,12 +34,12 @@ static void init (dict_t *this, char *key, data_t *value, void *data) { - void *handle = NULL; - char *auth_file = NULL; - auth_handle_t *auth_handle = NULL; - auth_fn_t authenticate = NULL; - int *error = NULL; - int ret = 0; + void *handle = NULL; + char *auth_file = NULL; + auth_handle_t *auth_handle = NULL; + auth_fn_t authenticate = NULL; + int *error = NULL; + int ret = 0; /* It gets over written */ error = data; @@ -78,6 +78,7 @@ init (dict_t *this, char *key, data_t *value, void *data) gf_log ("authenticate", GF_LOG_ERROR, "dlsym(gf_auth) on %s\n", dlerror ()); dict_set (this, key, data_from_dynptr (NULL, 0)); + dlclose (handle); *error = -1; return; } @@ -87,10 +88,17 @@ init (dict_t *this, char *key, data_t *value, void *data) if (!auth_handle) { dict_set (this, key, data_from_dynptr (NULL, 0)); *error = -1; + dlclose (handle); return; } auth_handle->vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), gf_common_mt_volume_opt_list_t); + if (!auth_handle->vol_opt) { + dict_set (this, key, data_from_dynptr (NULL, 0)); + *error = -1; + dlclose (handle); + return; + } auth_handle->vol_opt->given_opt = dlsym (handle, "options"); if (auth_handle->vol_opt->given_opt == NULL) { gf_log ("authenticate", GF_LOG_DEBUG, diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index c218a673548..2f9b475abc1 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -1032,15 +1032,15 @@ int32_t posix_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, dict_t *xdata) { - int32_t op_ret = -1; - int32_t op_errno = 0; - char *real_path = NULL; - char *par_path = NULL; - int32_t fd = -1; - struct iatt stbuf; - struct posix_private *priv = NULL; - struct iatt preparent = {0,}; - struct iatt postparent = {0,}; + int32_t op_ret = -1; + int32_t op_errno = 0; + char *real_path = NULL; + char *par_path = NULL; + int32_t fd = -1; + struct iatt stbuf = {0,}; + struct posix_private *priv = NULL; + struct iatt preparent = {0,}; + struct iatt postparent = {0,}; DECLARE_OLD_FS_ID_VAR; @@ -3748,27 +3748,22 @@ int32_t posix_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, int32_t len, dict_t *xdata) { - char *buf = NULL; - - int _fd = -1; - - struct posix_fd *pfd = NULL; - - int op_ret = -1; - int op_errno = 0; - - int ret = 0; - - int32_t weak_checksum = 0; - unsigned char strong_checksum[MD5_DIGEST_LENGTH]; + char *buf = NULL; + int _fd = -1; + struct posix_fd *pfd = NULL; + int op_ret = -1; + int op_errno = 0; + int ret = 0; + int32_t weak_checksum = 0; + unsigned char strong_checksum[MD5_DIGEST_LENGTH]; VALIDATE_OR_GOTO (frame, out); VALIDATE_OR_GOTO (this, out); VALIDATE_OR_GOTO (fd, out); memset (strong_checksum, 0, MD5_DIGEST_LENGTH); - buf = GF_CALLOC (1, len, gf_posix_mt_char); + buf = GF_CALLOC (1, len, gf_posix_mt_char); if (!buf) { op_errno = ENOMEM; goto out; @@ -3797,12 +3792,14 @@ posix_rchecksum (call_frame_t *frame, xlator_t *this, weak_checksum = gf_rsync_weak_checksum ((unsigned char *) buf, (size_t) len); gf_rsync_strong_checksum ((unsigned char *) buf, (size_t) len, (unsigned char *) strong_checksum); - GF_FREE (buf); - op_ret = 0; out: STACK_UNWIND_STRICT (rchecksum, frame, op_ret, op_errno, weak_checksum, strong_checksum, NULL); + + if (buf) + GF_FREE (buf); + return 0; } -- cgit