diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-08 21:36:28 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-09-04 05:09:09 +0000 |
commit | 5276e8f27e3021d5da3d3055caed6f9a1d964c93 (patch) | |
tree | 23f6a1fedc8d5bf4b752eab2ae5a451c57a80fa0 /xlators/cluster/afr | |
parent | 81cbbfd1d870bea49b8aafe7bebb9e8251190918 (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 'xlators/cluster/afr')
-rw-r--r-- | xlators/cluster/afr/src/afr-inode-read.c | 24 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.c | 4 |
2 files changed, 15 insertions, 13 deletions
diff --git a/xlators/cluster/afr/src/afr-inode-read.c b/xlators/cluster/afr/src/afr-inode-read.c index 2675af2bf99..d0b07e9064f 100644 --- a/xlators/cluster/afr/src/afr-inode-read.c +++ b/xlators/cluster/afr/src/afr-inode-read.c @@ -1186,7 +1186,7 @@ afr_fgetxattr_pathinfo_cbk (call_frame_t *frame, void *cookie, xattr = gf_strdup (xattr); - (void)snprintf (xattr_cky, 1024, "%s-%ld", + (void)snprintf (xattr_cky, sizeof(xattr_cky), "%s-%ld", local->cont.getxattr.name, cky); ret = dict_set_dynstr (local->dict, xattr_cky, xattr); @@ -1217,20 +1217,21 @@ unlock: + SLEN (AFR_PATHINFO_HEADER) + 4; local->cont.getxattr.xattr_len += (padding + 2); - xattr_serz = GF_CALLOC (local->cont.getxattr.xattr_len, - sizeof (char), gf_common_mt_char); + xattr_serz = GF_MALLOC (local->cont.getxattr.xattr_len, + gf_common_mt_char); if (!xattr_serz) goto unwind; /* the xlator info */ - (void) sprintf (xattr_serz, "(<"AFR_PATHINFO_HEADER"%s> ", - this->name); + int xattr_serz_len = sprintf (xattr_serz, + "(<"AFR_PATHINFO_HEADER"%s> ", + this->name); /* actual series of pathinfo */ ret = dict_serialize_value_with_delim (local->dict, xattr_serz - + strlen (xattr_serz), + + xattr_serz_len, &tlen, ' '); if (ret) { goto unwind; @@ -1342,19 +1343,20 @@ unlock: padding += strlen (this->name) + SLEN (AFR_PATHINFO_HEADER) + 4; local->cont.getxattr.xattr_len += (padding + 2); - xattr_serz = GF_CALLOC (local->cont.getxattr.xattr_len, - sizeof (char), gf_common_mt_char); + xattr_serz = GF_MALLOC (local->cont.getxattr.xattr_len, + gf_common_mt_char); if (!xattr_serz) goto unwind; /* the xlator info */ - (void) sprintf (xattr_serz, "(<"AFR_PATHINFO_HEADER"%s> ", - this->name); + int xattr_serz_len = sprintf (xattr_serz, + "(<"AFR_PATHINFO_HEADER"%s> ", + this->name); /* actual series of pathinfo */ ret = dict_serialize_value_with_delim (local->dict, - xattr_serz + strlen (xattr_serz), + xattr_serz + xattr_serz_len, &tlen, ' '); if (ret) { goto unwind; diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c index dac714d5d2c..bde9a97a4e7 100644 --- a/xlators/cluster/afr/src/afr.c +++ b/xlators/cluster/afr/src/afr.c @@ -542,8 +542,8 @@ init (xlator_t *this) priv->child_up = GF_CALLOC (sizeof (unsigned char), child_count, gf_afr_mt_char); - priv->child_latency = GF_CALLOC (sizeof (*priv->child_latency), - child_count, + priv->child_latency = GF_MALLOC (sizeof (*priv->child_latency) + * child_count, gf_afr_mt_child_latency_t); if (!priv->child_up || !priv->child_latency) { |