summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src
diff options
context:
space:
mode:
authorAmar Tumballi <amarts@redhat.com>2012-04-13 17:29:41 +0530
committerAnand Avati <avati@redhat.com>2012-04-23 14:52:57 -0700
commit29f2de478cc6a475e6ae760d9cbe7ac847e9d79c (patch)
tree621fbb33e6e3de20f7c1b59a98e181c7b50b4796 /xlators/mgmt/glusterd/src
parent4c9e8fad23836d87b0c4327e990c789630fe5b97 (diff)
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 <amarts@redhat.com> BUG: 789278 Reviewed-on: http://review.gluster.com/3145 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-geo-rep.c14
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handshake.c4
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rpc-ops.c28
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c9
8 files changed, 47 insertions, 25 deletions
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;
}