summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-08 21:41:21 +0300
committerAmar Tumballi <amarts@redhat.com>2018-09-07 03:40:47 +0000
commit50e8b0c335ba4f18987a32e8268ee31498323beb (patch)
treed9f46df1e5b722debe2708ae10efbb701dade848
parentce17a3a66dd15f09d1bf5404f7f3dee860ca6f8c (diff)
glusterfsd/src/glusterfsd.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 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: Iaed86fcc909022c5158c3e08a9106b1110b9df0a
-rw-r--r--glusterfsd/src/glusterfsd.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index 5cc4704ac95..f374a2af22f 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -827,12 +827,12 @@ gf_remember_xlator_option (char *arg)
goto out;
}
- option->volume = GF_CALLOC ((dot - arg) + 1, sizeof (char),
- gfd_mt_char);
+ option->volume = GF_MALLOC ((dot - arg) + 1, gfd_mt_char);
if (!option->volume)
goto out;
strncpy (option->volume, arg, (dot - arg));
+ option->volume[(dot - arg)] = '\0';
equals = strchr (arg, '=');
if (!equals) {
@@ -841,12 +841,12 @@ gf_remember_xlator_option (char *arg)
goto out;
}
- option->key = GF_CALLOC ((equals - dot) + 1, sizeof (char),
- gfd_mt_char);
+ option->key = GF_MALLOC ((equals - dot) + 1, gfd_mt_char);
if (!option->key)
goto out;
strncpy (option->key, dot + 1, (equals - dot - 1));
+ option->key[(equals - dot - 1)] = '\0';
if (!*(equals + 1)) {
gf_msg ("", GF_LOG_WARNING, 0, glusterfsd_msg_10,
@@ -2153,7 +2153,7 @@ parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx)
if (cmd_args->thin_client) {
len = strlen (cmd_args->volfile_id) + SLEN ("gfproxy-client/");
- thin_volfileid = GF_CALLOC (1, len + 1, gf_common_mt_char);
+ thin_volfileid = GF_MALLOC (len + 1, gf_common_mt_char);
snprintf (thin_volfileid, len + 1, "gfproxy-client/%s",
cmd_args->volfile_id);
GF_FREE (cmd_args->volfile_id);