From 81cbbfd1d870bea49b8aafe7bebb9e8251190918 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Sat, 4 Aug 2018 09:51:26 +0300 Subject: 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 Signed-off-by: Yaniv Kaul Signed-off-by: Yaniv Kaul Change-Id: Ibda6f33dd180b7f7694f20a12af1e9576fe197f5 --- xlators/features/bit-rot/src/bitd/bit-rot-scrub.c | 5 ++--- xlators/features/bit-rot/src/bitd/bit-rot.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'xlators/features/bit-rot/src/bitd') 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 " -- cgit