summaryrefslogtreecommitdiffstats
path: root/xlators/encryption/crypt/src/crypt.c
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/encryption/crypt/src/crypt.c
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/encryption/crypt/src/crypt.c')
-rw-r--r--xlators/encryption/crypt/src/crypt.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/xlators/encryption/crypt/src/crypt.c b/xlators/encryption/crypt/src/crypt.c
index f6e1823ce66..93d64c82a9e 100644
--- a/xlators/encryption/crypt/src/crypt.c
+++ b/xlators/encryption/crypt/src/crypt.c
@@ -43,7 +43,7 @@ static crypt_local_t *crypt_alloc_local(call_frame_t *frame, xlator_t *this,
{
crypt_local_t *local = NULL;
- local = GF_CALLOC (1, sizeof (*local), gf_crypt_mt_local);
+ local = GF_CALLOC (1, sizeof (crypt_local_t), gf_crypt_mt_local);
if (!local) {
gf_log(this->name, GF_LOG_ERROR, "out of memory");
return NULL;
@@ -92,7 +92,7 @@ static struct crypt_inode_info *alloc_inode_info(crypt_local_t *local,
{
struct crypt_inode_info *info;
- info = GF_CALLOC(1, sizeof(*info), gf_crypt_mt_inode);
+ info = GF_CALLOC(1, sizeof(struct crypt_inode_info), gf_crypt_mt_inode);
if (!info) {
local->op_ret = -1;
local->op_errno = ENOMEM;
@@ -100,9 +100,8 @@ static struct crypt_inode_info *alloc_inode_info(crypt_local_t *local,
"Can not allocate inode info");
return NULL;
}
- memset(info, 0, sizeof(*info));
#if DEBUG_CRYPT
- info->loc = GF_CALLOC(1, sizeof(*loc), gf_crypt_mt_loc);
+ info->loc = GF_CALLOC(1, sizeof(loc_t), gf_crypt_mt_loc);
if (!info->loc) {
gf_log("crypt", GF_LOG_WARNING, "Can not allocate loc");
GF_FREE(info);
@@ -2181,12 +2180,11 @@ static int32_t crypt_open(call_frame_t *frame,
local = crypt_alloc_local(frame, this, GF_FOP_OPEN);
if (!local)
goto error;
- local->loc = GF_CALLOC(1, sizeof(*loc), gf_crypt_mt_loc);
+ local->loc = GF_CALLOC(1, sizeof(loc_t), gf_crypt_mt_loc);
if (!local->loc) {
ret = ENOMEM;
goto error;
}
- memset(local->loc, 0, sizeof(*local->loc));
ret = loc_copy(local->loc, loc);
if (ret) {
GF_FREE(local->loc);
@@ -3261,10 +3259,9 @@ static int32_t linkop_grab_local(call_frame_t *frame,
}
local->fd = fd;
local->flags = flags;
- local->loc = GF_CALLOC(1, sizeof(*oldloc), gf_crypt_mt_loc);
+ local->loc = GF_CALLOC(1, sizeof(loc_t), gf_crypt_mt_loc);
if (!local->loc)
goto error;
- memset(local->loc, 0, sizeof(*local->loc));
ret = loc_copy(local->loc, oldloc);
if (ret) {
GF_FREE(local->loc);
@@ -3272,13 +3269,12 @@ static int32_t linkop_grab_local(call_frame_t *frame,
goto error;
}
if (newloc) {
- local->newloc = GF_CALLOC(1, sizeof(*newloc), gf_crypt_mt_loc);
+ local->newloc = GF_CALLOC(1, sizeof(loc_t), gf_crypt_mt_loc);
if (!local->newloc) {
loc_wipe(local->loc);
GF_FREE(local->loc);
goto error;
}
- memset(local->newloc, 0, sizeof(*local->newloc));
ret = loc_copy(local->newloc, newloc);
if (ret) {
loc_wipe(local->loc);
@@ -3971,10 +3967,9 @@ static int32_t crypt_stat(call_frame_t *frame,
local = crypt_alloc_local(frame, this, GF_FOP_STAT);
if (!local)
goto error;
- local->loc = GF_CALLOC(1, sizeof(*loc), gf_crypt_mt_loc);
+ local->loc = GF_CALLOC(1, sizeof(loc_t), gf_crypt_mt_loc);
if (!local->loc)
goto error;
- memset(local->loc, 0, sizeof(*local->loc));
ret = loc_copy(local->loc, loc);
if (ret) {
GF_FREE(local->loc);
@@ -4052,10 +4047,9 @@ static int32_t crypt_lookup(call_frame_t *frame,
local = crypt_alloc_local(frame, this, GF_FOP_LOOKUP);
if (!local)
goto error;
- local->loc = GF_CALLOC(1, sizeof(*loc), gf_crypt_mt_loc);
+ local->loc = GF_CALLOC(1, sizeof(loc_t), gf_crypt_mt_loc);
if (!local->loc)
goto error;
- memset(local->loc, 0, sizeof(*local->loc));
ret = loc_copy(local->loc, loc);
if (ret) {
GF_FREE(local->loc);