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 --- 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 ++++++++++++------------- 22 files changed, 121 insertions(+), 67 deletions(-) (limited to 'xlators') 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