summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2018-08-04 16:24:18 +0300
committerAmar Tumballi <amarts@redhat.com>2018-08-20 03:08:29 +0000
commitd7f97cef9099e8904d296df5cc9a221d295cfb35 (patch)
tree3d8f2a76ccfbb73b674dc1b0f4f1527affe82d8d /libglusterfs
parente924d76b125d50447535681e4525485379d45eeb (diff)
libguestfs/src/mem-pool.h: switch from calloc() to malloc()
If we are going to overwrite that allocated memory, why bother zero'ing it? Only compile-tested! updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: I9c9d2d8d5ab3e706c747feb1920ecd417807f7fd
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/mem-pool.h19
1 files changed, 5 insertions, 14 deletions
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
index a2a907a2344..9a457bbca5a 100644
--- a/libglusterfs/src/mem-pool.h
+++ b/libglusterfs/src/mem-pool.h
@@ -163,12 +163,13 @@ char *gf_strndup (const char *src, size_t len)
goto out;
}
- dup_str = GF_CALLOC (1, len + 1, gf_common_mt_strdup);
+ dup_str = GF_MALLOC (len + 1, gf_common_mt_strdup);
if (!dup_str) {
goto out;
}
memcpy (dup_str, src, len);
+ dup_str[len] = '\0';
out:
return dup_str;
}
@@ -176,20 +177,10 @@ out:
static inline
char * gf_strdup (const char *src)
{
-
- char *dup_str = NULL;
- size_t len = 0;
-
- len = strlen (src) + 1;
-
- dup_str = GF_CALLOC(1, len, gf_common_mt_strdup);
-
- if (!dup_str)
+ if (!src)
return NULL;
- memcpy (dup_str, src, len);
-
- return dup_str;
+ return gf_strndup (src, strlen (src));
}
static inline void *
@@ -197,7 +188,7 @@ gf_memdup (const void *src, size_t size)
{
void *dup_mem = NULL;
- dup_mem = GF_CALLOC(1, size, gf_common_mt_strdup);
+ dup_mem = GF_MALLOC (size, gf_common_mt_strdup);
if (!dup_mem)
goto out;