summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-08 21:36:28 +0300
committerAmar Tumballi <amarts@redhat.com>2018-09-04 05:09:09 +0000
commit5276e8f27e3021d5da3d3055caed6f9a1d964c93 (patch)
tree23f6a1fedc8d5bf4b752eab2ae5a451c57a80fa0
parent81cbbfd1d870bea49b8aafe7bebb9e8251190918 (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
-rw-r--r--cli/src/cli-cmd-global.c2
-rw-r--r--cli/src/cli-cmd-peer.c2
-rw-r--r--cli/src/cli-cmd-snapshot.c2
-rw-r--r--cli/src/cli-cmd-system.c2
-rw-r--r--cli/src/cli-cmd-volume.c14
-rw-r--r--cli/src/cli-rpc-ops.c4
-rw-r--r--cli/src/cli-xml-output.c2
-rw-r--r--extras/geo-rep/gsync-sync-gfid.c2
-rw-r--r--rpc/rpc-lib/src/rpc-clnt.c2
-rw-r--r--rpc/rpc-transport/socket/src/socket.c2
-rw-r--r--rpc/xdr/src/glusterfs3.h8
-rw-r--r--tests/basic/ec/ec-fast-fgetxattr.c2
-rw-r--r--tests/basic/gfapi/gfapi-async-calls-test.c2
-rw-r--r--tests/bugs/replicate/bug-1250170-fsync.c4
-rw-r--r--xlators/cluster/afr/src/afr-inode-read.c24
-rw-r--r--xlators/cluster/afr/src/afr.c4
-rw-r--r--xlators/cluster/dht/src/dht-common.c30
-rw-r--r--xlators/cluster/dht/src/dht-helper.c21
-rw-r--r--xlators/cluster/dht/src/dht-layout.c4
-rw-r--r--xlators/cluster/dht/src/tier.c6
-rw-r--r--xlators/cluster/stripe/src/stripe-helpers.c2
21 files changed, 77 insertions, 64 deletions
diff --git a/cli/src/cli-cmd-global.c b/cli/src/cli-cmd-global.c
index fb2ecb1d3de..3c8ae227ca7 100644
--- a/cli/src/cli-cmd-global.c
+++ b/cli/src/cli-cmd-global.c
@@ -57,7 +57,7 @@ cli_cmd_global_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
struct cli_cmd *global_cmd = NULL;
int count = 0;
- cmd = GF_CALLOC (1, sizeof (global_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (global_cmds), cli_mt_cli_cmd);
memcpy (cmd, global_cmds, sizeof (global_cmds));
count = (sizeof (global_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
diff --git a/cli/src/cli-cmd-peer.c b/cli/src/cli-cmd-peer.c
index 7df60bcb2be..a50ea7c66b5 100644
--- a/cli/src/cli-cmd-peer.c
+++ b/cli/src/cli-cmd-peer.c
@@ -284,7 +284,7 @@ cli_cmd_peer_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
cli_out ("\ngluster peer commands");
cli_out ("======================\n");
- cmd = GF_CALLOC (1, sizeof (cli_probe_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (cli_probe_cmds), cli_mt_cli_cmd);
memcpy (cmd, cli_probe_cmds, sizeof (cli_probe_cmds));
count = (sizeof (cli_probe_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index 06e00c96b7e..64cbd42ce5a 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -131,7 +131,7 @@ cli_cmd_snapshot_help_cbk (struct cli_state *state,
struct cli_cmd *snap_cmd = NULL;
int count = 0;
- cmd = GF_CALLOC (1, sizeof (snapshot_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (snapshot_cmds), cli_mt_cli_cmd);
memcpy (cmd, snapshot_cmds, sizeof (snapshot_cmds));
count = (sizeof (snapshot_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c
index c41594bfa59..995e1b1ad5c 100644
--- a/cli/src/cli-cmd-system.c
+++ b/cli/src/cli-cmd-system.c
@@ -592,7 +592,7 @@ cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
struct cli_cmd *system_cmd = NULL;
int count = 0;
- cmd = GF_CALLOC (1, sizeof (cli_system_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (cli_system_cmds), cli_mt_cli_cmd);
memcpy (cmd, cli_system_cmds, sizeof (cli_system_cmds));
count = (sizeof (cli_system_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index b9fd56362cf..d8b9e25f198 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -897,6 +897,7 @@ cli_event_remove_brick_str (dict_t *options, char **event_str,
int32_t i = 1;
int32_t count = 0;
int32_t eventstrlen = 1;
+ int bricklen = 0;
char *tmp_ptr = NULL;
if (!options || !event_str || !event)
@@ -971,8 +972,9 @@ cli_event_remove_brick_str (dict_t *options, char **event_str,
break;
}
snprintf (tmp_ptr, eventstrlen, "%s ", brick);
- eventstrlen -= (strlen (brick) + 1);
- tmp_ptr += (strlen (brick) + 1);
+ bricklen = strlen (brick);
+ eventstrlen -= (bricklen + 1);
+ tmp_ptr += (bricklen + 1);
i++;
}
@@ -3504,7 +3506,7 @@ cli_cmd_quota_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
struct cli_cmd *quota_cmd = NULL;
int count = 0;
- cmd = GF_CALLOC (1, sizeof (quota_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (quota_cmds), cli_mt_cli_cmd);
memcpy (cmd, quota_cmds, sizeof (quota_cmds));
count = (sizeof (quota_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
@@ -3531,7 +3533,7 @@ cli_cmd_bitrot_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
struct cli_cmd *bitrot_cmd = NULL;
int count = 0;
- cmd = GF_CALLOC (1, sizeof (bitrot_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (bitrot_cmds), cli_mt_cli_cmd);
memcpy (cmd, bitrot_cmds, sizeof (bitrot_cmds));
count = (sizeof (bitrot_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
@@ -3558,7 +3560,7 @@ cli_cmd_tier_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
struct cli_cmd *tier_cmd = NULL;
int count = 0;
- cmd = GF_CALLOC (1, sizeof (tier_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (tier_cmds), cli_mt_cli_cmd);
memcpy (cmd, tier_cmds, sizeof (tier_cmds));
count = (sizeof (tier_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
@@ -3584,7 +3586,7 @@ cli_cmd_volume_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
struct cli_cmd *vol_cmd = NULL;
int count = 0;
- cmd = GF_CALLOC (1, sizeof (volume_cmds), cli_mt_cli_cmd);
+ cmd = GF_MALLOC (sizeof (volume_cmds), cli_mt_cli_cmd);
memcpy (cmd, volume_cmds, sizeof (volume_cmds));
count = (sizeof (volume_cmds) / sizeof (struct cli_cmd));
cli_cmd_sort (cmd, count);
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 1e95836e4af..40bd64b983c 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -5848,7 +5848,7 @@ gf_cli_gsync_status_output (dict_t *dict, gf_boolean_t is_detail)
/* gsync_count = number of nodes reporting output.
each sts_val object will store output of each
node */
- sts_vals = GF_CALLOC (gsync_count, sizeof (gf_gsync_status_t *),
+ sts_vals = GF_MALLOC (gsync_count * sizeof (gf_gsync_status_t *),
gf_common_mt_char);
if (!sts_vals) {
ret = -1;
@@ -8326,7 +8326,7 @@ xml_end:
goto out;
}
- status.brick = GF_CALLOC (1, PATH_MAX + 256, gf_common_mt_strdup);
+ status.brick = GF_MALLOC (PATH_MAX + 256, gf_common_mt_strdup);
if (!status.brick) {
errno = ENOMEM;
ret = -1;
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
index dcb1715e625..fd42192162b 100644
--- a/cli/src/cli-xml-output.c
+++ b/cli/src/cli-xml-output.c
@@ -4138,7 +4138,7 @@ cli_xml_output_vol_gsync_status (dict_t *dict,
if (ret)
goto out;
- status_values = GF_CALLOC (count, sizeof (gf_gsync_status_t *),
+ status_values = GF_MALLOC (count * sizeof (gf_gsync_status_t *),
gf_common_mt_char);
if (!status_values) {
ret = -1;
diff --git a/extras/geo-rep/gsync-sync-gfid.c b/extras/geo-rep/gsync-sync-gfid.c
index 89b3ebc716e..4f4fde94e40 100644
--- a/extras/geo-rep/gsync-sync-gfid.c
+++ b/extras/geo-rep/gsync-sync-gfid.c
@@ -80,7 +80,7 @@ main (int argc, char *argv[])
/* gfid + '\0' + bname + '\0' */
len = UUID_CANONICAL_FORM_LEN + 1 + strlen (bname) + 1;
- blob = calloc (1, len);
+ blob = malloc (len);
memcpy (blob, gfid, UUID_CANONICAL_FORM_LEN);
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
index a4663648a38..9ee9161c904 100644
--- a/rpc/rpc-lib/src/rpc-clnt.c
+++ b/rpc/rpc-lib/src/rpc-clnt.c
@@ -1592,7 +1592,7 @@ rpcclnt_cbk_program_register (struct rpc_clnt *clnt,
goto out;
}
- tmp = GF_CALLOC (1, sizeof (*tmp),
+ tmp = GF_MALLOC (sizeof (*tmp),
gf_common_mt_rpcclnt_cb_program_t);
if (tmp == NULL) {
goto out;
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 9518bb9d9df..ff9423f1059 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -4522,7 +4522,7 @@ socket_init (rpc_transport_t *this)
return -1;
}
- priv = GF_CALLOC (1, sizeof (*priv), gf_common_mt_socket_private_t);
+ priv = GF_MALLOC (sizeof (*priv), gf_common_mt_socket_private_t);
if (!priv) {
return -1;
}
diff --git a/rpc/xdr/src/glusterfs3.h b/rpc/xdr/src/glusterfs3.h
index 7afa6dcf0ee..4ffad3c5b45 100644
--- a/rpc/xdr/src/glusterfs3.h
+++ b/rpc/xdr/src/glusterfs3.h
@@ -812,7 +812,7 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
xpair->value.gfx_value_u.value_dbl);
break;
case GF_DATA_TYPE_STR:
- value = GF_CALLOC (1, xpair->value.gfx_value_u.val_string.val_string_len + 1,
+ value = GF_MALLOC (xpair->value.gfx_value_u.val_string.val_string_len + 1,
gf_common_mt_char);
if (!value) {
errno = ENOMEM;
@@ -820,11 +820,12 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
}
memcpy (value, xpair->value.gfx_value_u.val_string.val_string_val,
xpair->value.gfx_value_u.val_string.val_string_len);
+ value[xpair->value.gfx_value_u.val_string.val_string_len] = '\0';
free (xpair->value.gfx_value_u.val_string.val_string_val);
ret = dict_set_dynstr (this, key, value);
break;
case GF_DATA_TYPE_GFUUID:
- uuid = GF_CALLOC (1, sizeof (uuid_t), gf_common_mt_uuid_t);
+ uuid = GF_MALLOC (sizeof (uuid_t), gf_common_mt_uuid_t);
if (!uuid) {
errno = ENOMEM;
goto out;
@@ -842,7 +843,7 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
ret = dict_set_iatt (this, key, iatt, false);
break;
case GF_DATA_TYPE_PTR:
- value = GF_CALLOC (1, xpair->value.gfx_value_u.other.other_len + 1,
+ value = GF_MALLOC (xpair->value.gfx_value_u.other.other_len + 1,
gf_common_mt_char);
if (!value) {
errno = ENOMEM;
@@ -850,6 +851,7 @@ xdr_to_dict (gfx_dict *dict, dict_t **to)
}
memcpy (value, xpair->value.gfx_value_u.other.other_val,
xpair->value.gfx_value_u.other.other_len);
+ value[xpair->value.gfx_value_u.other.other_len] = '\0';
free (xpair->value.gfx_value_u.other.other_val);
ret = dict_set_dynptr (this, key, value,
xpair->value.gfx_value_u.other.other_len);
diff --git a/tests/basic/ec/ec-fast-fgetxattr.c b/tests/basic/ec/ec-fast-fgetxattr.c
index ecdbcbe44a6..b40dda65de5 100644
--- a/tests/basic/ec/ec-fast-fgetxattr.c
+++ b/tests/basic/ec/ec-fast-fgetxattr.c
@@ -16,7 +16,7 @@ fill_iov (struct iovec *iov, char fillchar, int count)
{
int ret = -1;
- iov->iov_base = calloc (count + 1, sizeof(fillchar));
+ iov->iov_base = malloc (count + 1);
if (iov->iov_base == NULL) {
return ret;
} else {
diff --git a/tests/basic/gfapi/gfapi-async-calls-test.c b/tests/basic/gfapi/gfapi-async-calls-test.c
index 58046861668..b9f29a44ac0 100644
--- a/tests/basic/gfapi/gfapi-async-calls-test.c
+++ b/tests/basic/gfapi/gfapi-async-calls-test.c
@@ -21,7 +21,7 @@ fill_iov (struct iovec *iov, char fillchar, int count)
{
int ret = -1;
- iov->iov_base = calloc (count + 1, sizeof(fillchar));
+ iov->iov_base = malloc (count + 1);
if (iov->iov_base == NULL) {
return ret;
} else {
diff --git a/tests/bugs/replicate/bug-1250170-fsync.c b/tests/bugs/replicate/bug-1250170-fsync.c
index 1d3025bcd9f..421fb5c5067 100644
--- a/tests/bugs/replicate/bug-1250170-fsync.c
+++ b/tests/bugs/replicate/bug-1250170-fsync.c
@@ -26,9 +26,9 @@ int main (int argc, char **argv)
file = argv[1];
buf_size = 1024;
- buffer = calloc(1, buf_size);
+ buffer = malloc(buf_size);
if (!buffer) {
- perror("calloc");
+ perror("malloc");
return -1;
}
memset (buffer, 'R', buf_size);
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) {
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index 8a7b4bf5ff5..c7c7fbf22ba 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -4335,23 +4335,28 @@ fill_layout_info (dht_layout_t *layout, char *buf)
}
}
-void
+static void
dht_fill_pathinfo_xattr (xlator_t *this, dht_local_t *local,
char *xattr_buf, int32_t alloc_len,
int flag, char *layout_buf)
{
- if (flag && local->xattr_val)
- snprintf (xattr_buf, alloc_len,
+ if (flag) {
+ if (local->xattr_val) {
+ snprintf (xattr_buf, alloc_len,
"((<"DHT_PATHINFO_HEADER"%s> %s) (%s-layout %s))",
this->name, local->xattr_val, this->name,
layout_buf);
- else if (local->xattr_val)
+ } else {
+ snprintf (xattr_buf, alloc_len, "(%s-layout %s)",
+ this->name, layout_buf);
+ }
+ } else if (local->xattr_val) {
snprintf (xattr_buf, alloc_len,
"(<"DHT_PATHINFO_HEADER"%s> %s)",
this->name, local->xattr_val);
- else if (flag)
- snprintf (xattr_buf, alloc_len, "(%s-layout %s)",
- this->name, layout_buf);
+ } else {
+ xattr_buf[0] = '\0';
+ }
}
int
@@ -4360,7 +4365,6 @@ dht_vgetxattr_alloc_and_fill (dht_local_t *local, dict_t *xattr, xlator_t *this,
{
int ret = -1;
char *value = NULL;
- int32_t plen = 0;
ret = dict_get_str (xattr, local->xsel, &value);
if (ret) {
@@ -4375,16 +4379,17 @@ dht_vgetxattr_alloc_and_fill (dht_local_t *local, dict_t *xattr, xlator_t *this,
local->alloc_len += strlen(value);
if (!local->xattr_val) {
- local->alloc_len += (strlen (DHT_PATHINFO_HEADER) + 10);
- local->xattr_val = GF_CALLOC (local->alloc_len, sizeof (char),
+ local->alloc_len += sizeof (DHT_PATHINFO_HEADER) + 10;
+ local->xattr_val = GF_MALLOC (local->alloc_len,
gf_common_mt_char);
if (!local->xattr_val) {
ret = -1;
goto out;
}
+ local->xattr_val[0] = '\0';
}
- plen = strlen (local->xattr_val);
+ int plen = strlen (local->xattr_val);
if (plen) {
/* extra byte(s) for \0 to be safe */
local->alloc_len += (plen + 2);
@@ -4436,8 +4441,7 @@ dht_vgetxattr_fill_and_set (dht_local_t *local, dict_t **dict, xlator_t *this,
local->alloc_len += (2 * strlen (this->name))
+ strlen (layout_buf)
+ 40;
- xattr_buf = GF_CALLOC (local->alloc_len, sizeof (char),
- gf_common_mt_char);
+ xattr_buf = GF_MALLOC (local->alloc_len, gf_common_mt_char);
if (!xattr_buf)
goto out;
diff --git a/xlators/cluster/dht/src/dht-helper.c b/xlators/cluster/dht/src/dht-helper.c
index fc67a45c7ce..8bd3f564221 100644
--- a/xlators/cluster/dht/src/dht-helper.c
+++ b/xlators/cluster/dht/src/dht-helper.c
@@ -622,6 +622,9 @@ dht_filter_loc_subvol_key (xlator_t *this, loc_t *loc, loc_t *new_loc,
xlator_list_t *trav = NULL;
char key[1024] = {0,};
int ret = 0; /* not found */
+ int keylen = 0;
+ int name_len = 0;
+ int path_len = 0;
/* Why do other tasks if first required 'char' itself is not there */
if (!new_loc || !loc || !loc->name || !strchr (loc->name, '@')) {
@@ -631,24 +634,24 @@ dht_filter_loc_subvol_key (xlator_t *this, loc_t *loc, loc_t *new_loc,
trav = this->children;
while (trav) {
- snprintf (key, sizeof (key), "*@%s:%s", this->name, trav->xlator->name);
+ keylen = snprintf (key, sizeof (key), "*@%s:%s", this->name, trav->xlator->name);
if (fnmatch (key, loc->name, FNM_NOESCAPE) == 0) {
- new_name = GF_CALLOC(strlen (loc->name),
- sizeof (char),
+ name_len = strlen (loc->name);
+ new_name = GF_MALLOC(name_len,
gf_common_mt_char);
if (!new_name)
goto out;
if (fnmatch (key, loc->path, FNM_NOESCAPE) == 0) {
- new_path = GF_CALLOC(strlen (loc->path),
- sizeof (char),
+ path_len = strlen (loc->path);
+ new_path = GF_MALLOC(path_len,
gf_common_mt_char);
if (!new_path)
goto out;
- strncpy (new_path, loc->path, (strlen (loc->path) -
- strlen (key) + 1));
+ strncpy (new_path, loc->path, (path_len -
+ keylen + 1));
}
- strncpy (new_name, loc->name, (strlen (loc->name) -
- strlen (key) + 1));
+ strncpy (new_name, loc->name, (name_len -
+ keylen + 1));
if (new_loc) {
new_loc->path = ((new_path) ? new_path:
diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c
index 97b98e01451..6d9d4e693ff 100644
--- a/xlators/cluster/dht/src/dht-layout.c
+++ b/xlators/cluster/dht/src/dht-layout.c
@@ -201,8 +201,8 @@ dht_layouts_init (xlator_t *this, dht_conf_t *conf)
if (!conf)
goto out;
- conf->file_layouts = GF_CALLOC (conf->subvolume_cnt,
- sizeof (dht_layout_t *),
+ conf->file_layouts = GF_MALLOC (conf->subvolume_cnt
+ * sizeof (dht_layout_t *),
gf_dht_mt_dht_layout_t);
if (!conf->file_layouts) {
goto out;
diff --git a/xlators/cluster/dht/src/tier.c b/xlators/cluster/dht/src/tier.c
index 13ce7f4fb2b..63eb65be302 100644
--- a/xlators/cluster/dht/src/tier.c
+++ b/xlators/cluster/dht/src/tier.c
@@ -74,8 +74,8 @@ qfile_array_new (ssize_t array_size)
goto out;
}
- qfile_array->fd_array = GF_CALLOC (array_size, sizeof (int),
- gf_dht_mt_int32_t);
+ qfile_array->fd_array = GF_MALLOC (array_size * sizeof (int),
+ gf_dht_mt_int32_t);
if (!qfile_array->fd_array) {
gf_msg ("tier", GF_LOG_ERROR, 0, DHT_MSG_LOG_TIER_ERROR,
"Failed to allocate memory for "
@@ -2157,7 +2157,7 @@ tier_get_bricklist (xlator_t *xl, struct list_head *local_bricklist_head)
brickname);
local_brick->brick_db_path =
- GF_CALLOC (PATH_MAX, 1, gf_common_mt_char);
+ GF_MALLOC (PATH_MAX, gf_common_mt_char);
if (!local_brick->brick_db_path) {
gf_msg ("tier", GF_LOG_ERROR, 0,
DHT_MSG_LOG_TIER_STATUS,
diff --git a/xlators/cluster/stripe/src/stripe-helpers.c b/xlators/cluster/stripe/src/stripe-helpers.c
index 18f70fe6d7e..71ab608118f 100644
--- a/xlators/cluster/stripe/src/stripe-helpers.c
+++ b/xlators/cluster/stripe/src/stripe-helpers.c
@@ -269,7 +269,7 @@ stripe_fill_pathinfo_xattr (xlator_t *this, stripe_local_t *local,
+ strlen (stripe_size_str) + 7;
local->xattr_total_len += (padding + 2);
- pathinfo_serz = GF_CALLOC (local->xattr_total_len, sizeof (char),
+ pathinfo_serz = GF_MALLOC (local->xattr_total_len,
gf_common_mt_char);
if (!pathinfo_serz)
goto out;