From d7f97cef9099e8904d296df5cc9a221d295cfb35 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Sat, 4 Aug 2018 16:24:18 +0300 Subject: 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 Change-Id: I9c9d2d8d5ab3e706c747feb1920ecd417807f7fd --- libglusterfs/src/mem-pool.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'libglusterfs') 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; -- cgit