summaryrefslogtreecommitdiffstats
path: root/xlators/storage
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/storage
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/storage')
-rw-r--r--xlators/storage/bd/src/bd.c6
-rw-r--r--xlators/storage/posix/src/posix-helpers.c27
-rw-r--r--xlators/storage/posix/src/posix-inode-fd-ops.c17
3 files changed, 30 insertions, 20 deletions
diff --git a/xlators/storage/bd/src/bd.c b/xlators/storage/bd/src/bd.c
index 08dc35034f8..0f4ad16b024 100644
--- a/xlators/storage/bd/src/bd.c
+++ b/xlators/storage/bd/src/bd.c
@@ -993,10 +993,11 @@ bd_setx_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
goto out;
}
- param = copy = GF_CALLOC (1, local->data->len + 1, gf_common_mt_char);
+ param = copy = GF_MALLOC (local->data->len + 1, gf_common_mt_char);
BD_VALIDATE_MEM_ALLOC (param, op_errno, out);
strncpy (param, local->data->data, local->data->len);
+ param[local->data->len] = '\0';
type = strtok_r (param, ":", &p);
if (!type) {
@@ -1292,7 +1293,7 @@ bd_offload (call_frame_t *frame, xlator_t *this, loc_t *loc,
int op_errno = 0;
bd_local_t *local = frame->local;
- param = GF_CALLOC (1, local->data->len + 1, gf_common_mt_char);
+ param = GF_MALLOC (local->data->len + 1, gf_common_mt_char);
BD_VALIDATE_MEM_ALLOC (param, op_errno, out);
param_copy = param;
@@ -1303,6 +1304,7 @@ bd_offload (call_frame_t *frame, xlator_t *this, loc_t *loc,
BD_VALIDATE_MEM_ALLOC (local->dloc, op_errno, out);
strncpy (param, local->data->data, local->data->len);
+ param[local->data->len] = '\0';
gfid = strtok_r (param, ":", &p);
size = strtok_r (NULL, ":", &p);
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index b4d433e369d..bd5b6e6b98b 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -272,18 +272,21 @@ _posix_xattr_get_set_from_backend (posix_xattr_filler_t *filler, char *key)
}
if (xattr_size != -1) {
- value = GF_CALLOC (1, xattr_size + 1, gf_posix_mt_char);
+ value = GF_MALLOC (xattr_size + 1, gf_posix_mt_char);
if (!value)
goto out;
if (have_val) {
memcpy (value, val_buf, xattr_size);
- } else if (filler->real_path) {
- xattr_size = sys_lgetxattr (filler->real_path, key,
- value, xattr_size);
} else {
- xattr_size = sys_fgetxattr (filler->fdnum, key, value,
- xattr_size);
+ bzero(value, xattr_size + 1);
+ if (filler->real_path) {
+ xattr_size = sys_lgetxattr (filler->real_path,
+ key, value, xattr_size);
+ } else {
+ xattr_size = sys_fgetxattr (filler->fdnum, key,
+ value, xattr_size);
+ }
}
if (xattr_size == -1) {
if (filler->real_path)
@@ -2518,7 +2521,7 @@ posix_fetch_signature_xattr (char *real_path,
gf_boolean_t have_val = _gf_false;
xattrsize = sys_lgetxattr (real_path, key, val_buf,
- sizeof(val_buf) - 1);
+ sizeof(val_buf) - 1);
if (xattrsize >= 0) {
have_val = _gf_true;
} else {
@@ -2529,12 +2532,14 @@ posix_fetch_signature_xattr (char *real_path,
if (xattrsize == -1)
goto error_return;
}
- memptr = GF_CALLOC (xattrsize + 1, sizeof (char), gf_posix_mt_char);
+ memptr = GF_MALLOC (xattrsize + 1, gf_posix_mt_char);
if (!memptr)
goto error_return;
if (have_val) {
memcpy (memptr, val_buf, xattrsize);
+ memptr[xattrsize] = '\0';
} else {
+ bzero (memptr, xattrsize + 1);
ret = sys_lgetxattr (real_path, key, memptr, xattrsize);
if (ret == -1)
goto freemem;
@@ -2881,7 +2886,7 @@ posix_set_iatt_in_dict (dict_t *dict, struct iatt *preop, struct iatt *postop)
return ret;
if (postop) {
- stbuf = GF_CALLOC (1, len, gf_common_mt_char);
+ stbuf = GF_MALLOC (len, gf_common_mt_char);
if (!stbuf)
goto out;
memcpy (stbuf, postop, len);
@@ -2894,7 +2899,7 @@ posix_set_iatt_in_dict (dict_t *dict, struct iatt *preop, struct iatt *postop)
}
if (preop) {
- prebuf = GF_CALLOC (1, len, gf_common_mt_char);
+ prebuf = GF_MALLOC (len, gf_common_mt_char);
if (!prebuf)
goto out;
memcpy (prebuf, preop, len);
@@ -2906,7 +2911,7 @@ posix_set_iatt_in_dict (dict_t *dict, struct iatt *preop, struct iatt *postop)
}
if (postop) {
- postbuf = GF_CALLOC (1, len, gf_common_mt_char);
+ postbuf = GF_MALLOC (len, gf_common_mt_char);
if (!postbuf)
goto out;
memcpy (postbuf, postop, len);
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c
index 89355757508..ed5f439ac73 100644
--- a/xlators/storage/posix/src/posix-inode-fd-ops.c
+++ b/xlators/storage/posix/src/posix-inode-fd-ops.c
@@ -3224,7 +3224,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
goto out;
}
}
- value = GF_CALLOC (size + 1, sizeof(char), gf_posix_mt_char);
+ value = GF_MALLOC (size + 1, gf_posix_mt_char);
if (!value) {
op_ret = -1;
op_errno = ENOMEM;
@@ -3233,6 +3233,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
if (have_val) {
memcpy (value, value_buf, size);
} else {
+ bzero (value, size + 1);
size = sys_lgetxattr (real_path, key, value, size);
if (size == -1) {
op_ret = -1;
@@ -3349,8 +3350,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
goto out;
}
}
- value = GF_CALLOC (size + 1, sizeof(char),
- gf_posix_mt_char);
+ value = GF_MALLOC (size + 1, gf_posix_mt_char);
if (!value) {
op_errno = errno;
goto out;
@@ -3358,6 +3358,7 @@ posix_getxattr (call_frame_t *frame, xlator_t *this,
if (have_val) {
memcpy (value, value_buf, size);
} else {
+ bzero(value, size + 1);
size = sys_lgetxattr (real_path, keybuffer, value, size);
if (size == -1) {
op_errno = errno;
@@ -3533,7 +3534,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
goto done;
}
}
- value = GF_CALLOC (size + 1, sizeof(char), gf_posix_mt_char);
+ value = GF_MALLOC (size + 1, gf_posix_mt_char);
if (!value) {
op_ret = -1;
op_errno = ENOMEM;
@@ -3542,6 +3543,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
if (have_val) {
memcpy (value, value_buf, size);
} else {
+ bzero (value, size + 1);
size = sys_fgetxattr (_fd, key, value, size);
if (size == -1) {
op_ret = -1;
@@ -3639,8 +3641,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
break;
}
}
- value = GF_CALLOC (size + 1, sizeof(char),
- gf_posix_mt_char);
+ value = GF_MALLOC (size + 1, gf_posix_mt_char);
if (!value) {
op_ret = -1;
op_errno = errno;
@@ -3649,6 +3650,7 @@ posix_fgetxattr (call_frame_t *frame, xlator_t *this,
if (have_val) {
memcpy (value, value_buf, size);
} else {
+ bzero (value, size + 1);
size = sys_fgetxattr (_fd, key, value, size);
if (size == -1) {
op_ret = -1;
@@ -5046,11 +5048,12 @@ posix_readdirp_fill (xlator_t *this, fd_t *fd, gf_dirent_t *entries, dict_t *dic
hpath[len] = '/';
list_for_each_entry (entry, &entries->list, list) {
- memset (gfid, 0, 16);
inode = inode_grep (fd->inode->table, fd->inode,
entry->d_name);
if (inode)
gf_uuid_copy (gfid, inode->gfid);
+ else
+ bzero(gfid, 16);
strcpy (&hpath[len+1], entry->d_name);