summaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-08 21:36:28 +0300
committerAmar Tumballi <amarts@redhat.com>2018-09-04 05:09:09 +0000
commit5276e8f27e3021d5da3d3055caed6f9a1d964c93 (patch)
tree23f6a1fedc8d5bf4b752eab2ae5a451c57a80fa0 /rpc
parent81cbbfd1d870bea49b8aafe7bebb9e8251190918 (diff)
multiple files: calloc -> malloc
xlators/cluster/stripe/src/stripe-helpers.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/tier.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/dht-layout.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/dht-helper.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/dht/src/dht-common.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/afr/src/afr.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible xlators/cluster/afr/src/afr-inode-read.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible tests/bugs/replicate/bug-1250170-fsync.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible tests/basic/gfapi/gfapi-async-calls-test.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible tests/basic/ec/ec-fast-fgetxattr.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible rpc/xdr/src/glusterfs3.h: Move to GF_MALLOC() instead of GF_CALLOC() when possible rpc/rpc-transport/socket/src/socket.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible rpc/rpc-lib/src/rpc-clnt.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible extras/geo-rep/gsync-sync-gfid.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-xml-output.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-rpc-ops.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-volume.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-system.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-snapshot.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-peer.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible cli/src/cli-cmd-global.c: Move to GF_MALLOC() instead of GF_CALLOC() when possible It doesn't make sense to calloc (allocate and clear) memory when the code right away fills that memory with data. It may be optimized by the compiler, or have a microscopic performance improvement. In some cases, also changed allocation size to be sizeof some struct or type instead of a pointer - easier to read. In some cases, removed redundant strlen() calls by saving the result into a variable. 1. Only done for the straightforward cases. There's room for improvement. 2. Please review carefully, especially for string allocation, with the terminating NULL string. Only compile-tested! updates: bz#1193929 Original-Author: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Amar Tumballi <amarts@redhat.com> Change-Id: I16274dca4078a1d06ae09a0daf027d734b631ac2
Diffstat (limited to 'rpc')
-rw-r--r--rpc/rpc-lib/src/rpc-clnt.c2
-rw-r--r--rpc/rpc-transport/socket/src/socket.c2
-rw-r--r--rpc/xdr/src/glusterfs3.h8
3 files changed, 7 insertions, 5 deletions
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
index a4663648a38..9ee9161c904 100644
--- a/rpc/rpc-lib/src/rpc-clnt.c
+++ b/rpc/rpc-lib/src/rpc-clnt.c
@@ -1592,7 +1592,7 @@ rpcclnt_cbk_program_register (struct rpc_clnt *clnt,
goto out;
}
- tmp = GF_CALLOC (1, sizeof (*tmp),
+ tmp = GF_MALLOC (sizeof (*tmp),
gf_common_mt_rpcclnt_cb_program_t);
if (tmp == NULL) {
goto out;
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 9518bb9d9df..ff9423f1059 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -4522,7 +4522,7 @@ socket_init (rpc_transport_t *this)
return -1;
}
- priv = GF_CALLOC (1, sizeof (*priv), gf_common_mt_socket_private_t);
+ priv = GF_MALLOC (sizeof (*priv), gf_common_mt_socket_private_t);
if (!priv) {
return -1;
}
diff --git a/rpc/xdr/src/glusterfs3.h b/rpc/xdr/src/glusterfs3.h
index 7afa6dcf0ee..4ffad3c5b45 100644
--- a/rpc/xdr/src/glusterfs3.h
+++ b/rpc/xdr/src/glusterfs3.h
@@ -812,7 +812,7 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
xpair->value.gfx_value_u.value_dbl);
break;
case GF_DATA_TYPE_STR:
- value = GF_CALLOC (1, xpair->value.gfx_value_u.val_string.val_string_len + 1,
+ value = GF_MALLOC (xpair->value.gfx_value_u.val_string.val_string_len + 1,
gf_common_mt_char);
if (!value) {
errno = ENOMEM;
@@ -820,11 +820,12 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
}
memcpy (value, xpair->value.gfx_value_u.val_string.val_string_val,
xpair->value.gfx_value_u.val_string.val_string_len);
+ value[xpair->value.gfx_value_u.val_string.val_string_len] = '\0';
free (xpair->value.gfx_value_u.val_string.val_string_val);
ret = dict_set_dynstr (this, key, value);
break;
case GF_DATA_TYPE_GFUUID:
- uuid = GF_CALLOC (1, sizeof (uuid_t), gf_common_mt_uuid_t);
+ uuid = GF_MALLOC (sizeof (uuid_t), gf_common_mt_uuid_t);
if (!uuid) {
errno = ENOMEM;
goto out;
@@ -842,7 +843,7 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
ret = dict_set_iatt (this, key, iatt, false);
break;
case GF_DATA_TYPE_PTR:
- value = GF_CALLOC (1, xpair->value.gfx_value_u.other.other_len + 1,
+ value = GF_MALLOC (xpair->value.gfx_value_u.other.other_len + 1,
gf_common_mt_char);
if (!value) {
errno = ENOMEM;
@@ -850,6 +851,7 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
}
memcpy (value, xpair->value.gfx_value_u.other.other_val,
xpair->value.gfx_value_u.other.other_len);
+ value[xpair->value.gfx_value_u.other.other_len] = '\0';
free (xpair->value.gfx_value_u.other.other_val);
ret = dict_set_dynptr (this, key, value,
xpair->value.gfx_value_u.other.other_len);