summaryrefslogtreecommitdiffstats
path: root/xlators/features
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-04 09:51:26 +0300
committerAmar Tumballi <amarts@redhat.com>2018-09-04 04:58:14 +0000
commit81cbbfd1d870bea49b8aafe7bebb9e8251190918 (patch)
tree48e02860d8ddc43067ab1836adba90f8a03a14d7 /xlators/features
parent4cfbdfd0c851e4a5c6f4303a9141f34f8887b376 (diff)
Multiple files: calloc -> malloc
xlators/storage/posix/src/posix-inode-fd-ops.c: xlators/storage/posix/src/posix-helpers.c: xlators/storage/bd/src/bd.c: xlators/protocol/client/src/client-lk.c: xlators/performance/quick-read/src/quick-read.c: xlators/performance/io-cache/src/page.c xlators/nfs/server/src/nfs3-helpers.c xlators/nfs/server/src/nfs-fops.c xlators/nfs/server/src/mount3udp_svc.c xlators/nfs/server/src/mount3.c xlators/mount/fuse/src/fuse-helpers.c xlators/mount/fuse/src/fuse-bridge.c xlators/mgmt/glusterd/src/glusterd-utils.c xlators/mgmt/glusterd/src/glusterd-syncop.h xlators/mgmt/glusterd/src/glusterd-snapshot.c xlators/mgmt/glusterd/src/glusterd-rpc-ops.c xlators/mgmt/glusterd/src/glusterd-replace-brick.c xlators/mgmt/glusterd/src/glusterd-op-sm.c xlators/mgmt/glusterd/src/glusterd-mgmt.c xlators/meta/src/subvolumes-dir.c xlators/meta/src/graph-dir.c xlators/features/trash/src/trash.c xlators/features/shard/src/shard.h xlators/features/shard/src/shard.c xlators/features/marker/src/marker-quota.c xlators/features/locks/src/common.c xlators/features/leases/src/leases-internal.c xlators/features/gfid-access/src/gfid-access.c xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c xlators/features/bit-rot/src/bitd/bit-rot.c xlators/features/bit-rot/src/bitd/bit-rot-scrub.c bxlators/encryption/crypt/src/metadata.c xlators/encryption/crypt/src/crypt.c xlators/performance/md-cache/src/md-cache.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! .. and allocate memory as much as needed. xlators/nfs/server/src/mount3.c : Don't blindly allocate PATH_MAX, but strlen() the string and allocate appropriately. Also, align error messges. updates: bz#1193929 Original-Author: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: Ibda6f33dd180b7f7694f20a12af1e9576fe197f5
Diffstat (limited to 'xlators/features')
-rw-r--r--xlators/features/bit-rot/src/bitd/bit-rot-scrub.c5
-rw-r--r--xlators/features/bit-rot/src/bitd/bit-rot.c2
-rw-r--r--xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c2
-rw-r--r--xlators/features/gfid-access/src/gfid-access.c9
-rw-r--r--xlators/features/leases/src/leases-internal.c2
-rw-r--r--xlators/features/locks/src/common.c2
-rw-r--r--xlators/features/marker/src/marker-quota.c2
-rw-r--r--xlators/features/shard/src/shard.c8
-rw-r--r--xlators/features/shard/src/shard.h6
-rw-r--r--xlators/features/trash/src/trash.c7
10 files changed, 23 insertions, 22 deletions
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
index 8e432aee645..e2665acab98 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot-scrub.c
@@ -127,7 +127,7 @@ bitd_scrub_post_compute_check (xlator_t *this,
}
signlen = signptr->signaturelen;
- *signature = GF_CALLOC (1, sizeof (br_isignature_out_t) + signlen,
+ *signature = GF_MALLOC (sizeof (br_isignature_out_t) + signlen,
gf_common_mt_char);
(void) memcpy (*signature, signptr,
@@ -389,8 +389,7 @@ br_scrubber_scrub_begin (xlator_t *this, struct br_fsscan_entry *fsentry)
goto unrefd; /* skip this object */
/* if all's good, proceed to calculate the hash */
- md = GF_CALLOC (SHA256_DIGEST_LENGTH, sizeof (*md),
- gf_common_mt_char);
+ md = GF_MALLOC (SHA256_DIGEST_LENGTH, gf_common_mt_char);
if (!md)
goto unrefd;
diff --git a/xlators/features/bit-rot/src/bitd/bit-rot.c b/xlators/features/bit-rot/src/bitd/bit-rot.c
index 66e58948fa9..cf59232263b 100644
--- a/xlators/features/bit-rot/src/bitd/bit-rot.c
+++ b/xlators/features/bit-rot/src/bitd/bit-rot.c
@@ -393,7 +393,7 @@ br_object_read_sign (inode_t *linked_inode, fd_t *fd, br_object_t *object,
this = object->this;
- md = GF_CALLOC (SHA256_DIGEST_LENGTH, sizeof (*md), gf_common_mt_char);
+ md = GF_MALLOC (SHA256_DIGEST_LENGTH, gf_common_mt_char);
if (!md) {
gf_msg (this->name, GF_LOG_ERROR, ENOMEM, BRB_MSG_NO_MEMORY,
"failed to allocate memory for saving hash of the "
diff --git a/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c b/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c
index dc6a598fa81..e36bf71e4ae 100644
--- a/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c
+++ b/xlators/features/cloudsync/src/cloudsync-plugins/src/cloudsyncs3/src/libcloudsyncs3.c
@@ -298,7 +298,7 @@ aws_b64_encode(const unsigned char *input, int length)
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
- buff = GF_CALLOC(1, (bptr->length), gf_common_mt_char);
+ buff = GF_MALLOC(bptr->length, gf_common_mt_char);
memcpy(buff, bptr->data, bptr->length - 1);
buff[bptr->length - 1] = 0;
diff --git a/xlators/features/gfid-access/src/gfid-access.c b/xlators/features/gfid-access/src/gfid-access.c
index 0a82321ed3c..79c2ee911cd 100644
--- a/xlators/features/gfid-access/src/gfid-access.c
+++ b/xlators/features/gfid-access/src/gfid-access.c
@@ -140,7 +140,7 @@ ga_newfile_parse_args (xlator_t *this, data_t *data)
goto err;
}
- args->bname = GF_CALLOC (1, (len + 1), gf_common_mt_char);
+ args->bname = GF_MALLOC (len + 1, gf_common_mt_char);
if (args->bname == NULL)
goto err;
@@ -181,7 +181,7 @@ ga_newfile_parse_args (xlator_t *this, data_t *data)
args->gfid);
goto err;
}
- args->args.symlink.linkpath = GF_CALLOC (1, len + 1,
+ args->args.symlink.linkpath = GF_MALLOC (len + 1,
gf_common_mt_char);
if (args->args.symlink.linkpath == NULL)
goto err;
@@ -265,11 +265,12 @@ ga_heal_parse_args (xlator_t *this, data_t *data)
if (len == blob_len)
goto err;
- args->bname = GF_CALLOC (1, len + 1, gf_common_mt_char);
+ args->bname = GF_MALLOC (len + 1, gf_common_mt_char);
if (!args->bname)
goto err;
memcpy (args->bname, blob, len);
+ args->bname[len] = '\0';
blob_len -= (len + 1);
if (blob_len)
@@ -318,7 +319,7 @@ ga_fill_tmp_loc (loc_t *loc, xlator_t *this, uuid_t gfid,
new_loc->name++;
}
- gfid_ptr = GF_CALLOC (1, sizeof(uuid_t), gf_common_mt_uuid_t);
+ gfid_ptr = GF_MALLOC (sizeof(uuid_t), gf_common_mt_uuid_t);
if (!gfid_ptr) {
ret = -1;
goto out;
diff --git a/xlators/features/leases/src/leases-internal.c b/xlators/features/leases/src/leases-internal.c
index 475576eac79..fd0996e3943 100644
--- a/xlators/features/leases/src/leases-internal.c
+++ b/xlators/features/leases/src/leases-internal.c
@@ -900,7 +900,7 @@ __recall_lease (xlator_t *this, lease_inode_ctx_t *lease_ctx)
if (!timer) {
goto out;
}
- timer_data = GF_CALLOC (1, sizeof (*timer_data),
+ timer_data = GF_MALLOC (sizeof (lease_timer_data_t),
gf_leases_mt_timer_data_t);
if (!timer_data) {
GF_FREE (timer);
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c
index 324187a4a7a..b4d8aa37219 100644
--- a/xlators/features/locks/src/common.c
+++ b/xlators/features/locks/src/common.c
@@ -521,7 +521,7 @@ __copy_lock(posix_lock_t *src)
{
posix_lock_t *dst;
- dst = GF_CALLOC(1, sizeof(posix_lock_t), gf_locks_mt_posix_lock_t);
+ dst = GF_MALLOC(sizeof(posix_lock_t), gf_locks_mt_posix_lock_t);
if (dst != NULL) {
memcpy (dst, src, sizeof(posix_lock_t));
dst->client_uid = gf_strdup(src->client_uid);
diff --git a/xlators/features/marker/src/marker-quota.c b/xlators/features/marker/src/marker-quota.c
index 620201d616e..6d3c5eaec23 100644
--- a/xlators/features/marker/src/marker-quota.c
+++ b/xlators/features/marker/src/marker-quota.c
@@ -332,7 +332,7 @@ quota_dict_set_size_meta (xlator_t *this, dict_t *dict,
quota_meta_t *value = NULL;
char size_key[QUOTA_KEY_MAX] = {0, };
- value = GF_CALLOC (2, sizeof (quota_meta_t), gf_common_quota_meta_t);
+ value = GF_MALLOC (2 * sizeof (quota_meta_t), gf_common_quota_meta_t);
if (value == NULL) {
goto out;
}
diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c
index 6c075ac5bf7..a12e553f95f 100644
--- a/xlators/features/shard/src/shard.c
+++ b/xlators/features/shard/src/shard.c
@@ -1357,7 +1357,7 @@ shard_lookup_internal_dir (call_frame_t *frame, xlator_t *this,
priv = this->private;
local->post_res_handler = post_res_handler;
- gfid = GF_CALLOC (1, sizeof(uuid_t), gf_common_mt_uuid_t);
+ gfid = GF_MALLOC (sizeof(uuid_t), gf_common_mt_uuid_t);
if (!gfid)
goto err;
@@ -1378,6 +1378,7 @@ shard_lookup_internal_dir (call_frame_t *frame, xlator_t *this,
loc = &local->dot_shard_rm_loc;
break;
default:
+ bzero(*gfid, sizeof(uuid_t));
break;
}
@@ -2266,7 +2267,7 @@ shard_create_gfid_dict (dict_t *dict)
if (!new)
return NULL;
- gfid = GF_CALLOC (1, sizeof (uuid_t), gf_common_mt_char);
+ gfid = GF_MALLOC (sizeof (uuid_t), gf_common_mt_char);
if (!gfid) {
ret = -1;
goto out;
@@ -5615,7 +5616,7 @@ shard_mkdir_internal_dir (call_frame_t *frame, xlator_t *this,
priv = this->private;
local->post_res_handler = handler;
- gfid = GF_CALLOC (1, sizeof(uuid_t), gf_common_mt_uuid_t);
+ gfid = GF_MALLOC (sizeof(uuid_t), gf_common_mt_uuid_t);
if (!gfid)
goto err;
@@ -5629,6 +5630,7 @@ shard_mkdir_internal_dir (call_frame_t *frame, xlator_t *this,
loc = &local->dot_shard_rm_loc;
break;
default:
+ bzero(*gfid, sizeof(uuid_t));
break;
}
diff --git a/xlators/features/shard/src/shard.h b/xlators/features/shard/src/shard.h
index ac3813c8c50..7a263f4c37b 100644
--- a/xlators/features/shard/src/shard.h
+++ b/xlators/features/shard/src/shard.h
@@ -120,7 +120,7 @@ shard_unlock_entrylk (call_frame_t *frame, xlator_t *this);
int64_t *__size_attr = NULL; \
uint64_t *__bs = 0; \
\
- __bs = GF_CALLOC (1, sizeof (uint64_t), gf_shard_mt_uint64_t); \
+ __bs = GF_MALLOC (sizeof (uint64_t), gf_shard_mt_uint64_t); \
if (!__bs) \
goto label; \
*__bs = hton64 (block_size); \
@@ -142,8 +142,8 @@ shard_unlock_entrylk (call_frame_t *frame, xlator_t *this);
__size_attr, 8 * 4); \
if (__ret) { \
gf_msg (this->name, GF_LOG_WARNING, 0, \
- SHARD_MSG_DICT_OP_FAILED, "Failed to set key: %s " \
- "on path %s", GF_XATTR_SHARD_FILE_SIZE, (loc)->path); \
+ SHARD_MSG_DICT_OP_FAILED, "Failed to set key: %s " \
+ "on path %s", GF_XATTR_SHARD_FILE_SIZE, (loc)->path); \
GF_FREE (__size_attr); \
goto label; \
} \
diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c
index a59b186add1..9e429e38fe7 100644
--- a/xlators/features/trash/src/trash.c
+++ b/xlators/features/trash/src/trash.c
@@ -485,8 +485,7 @@ trash_dir_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (!data) {
goto out;
}
- priv->oldtrash_dir = GF_CALLOC (1, PATH_MAX,
- gf_common_mt_char);
+ priv->oldtrash_dir = GF_MALLOC (PATH_MAX, gf_common_mt_char);
if (!priv->oldtrash_dir) {
gf_log (this->name, GF_LOG_ERROR, "out of memory");
ret = ENOMEM;
@@ -541,7 +540,7 @@ trash_internalop_dir_lookup_cbk (call_frame_t *frame, void *cookie,
local = frame->local;
if (op_ret != 0 && op_errno == ENOENT) {
loc_wipe (&local->loc);
- gfid_ptr = GF_CALLOC (1, sizeof(uuid_t),
+ gfid_ptr = GF_MALLOC (sizeof(uuid_t),
gf_common_mt_uuid_t);
if (!gfid_ptr) {
ret = ENOMEM;
@@ -657,7 +656,7 @@ trash_dir_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
"directory %s ",
priv->newtrash_dir);
- gfid_ptr = GF_CALLOC (1, sizeof(uuid_t),
+ gfid_ptr = GF_MALLOC (sizeof(uuid_t),
gf_common_mt_uuid_t);
if (!gfid_ptr) {
ret = ENOMEM;