diff --git a/src/libs/zbxcommon/str.c b/src/libs/zbxcommon/str.c
index 2b14f6bb089..c9c48b766ae 100644
--- a/src/libs/zbxcommon/str.c
+++ b/src/libs/zbxcommon/str.c
@@ -653,17 +653,21 @@ char	*zbx_str_printable_dyn(const char *text)
  ******************************************************************************/
 size_t	zbx_strlcpy(char *dst, const char *src, size_t siz)
 {
-	const char	*s = src;
+	size_t	len = strlen(src);
 
-	if (0 != siz)
+	if (len + 1 <= siz)
 	{
-		while (0 != --siz && '\0' != *s)
-			*dst++ = *s++;
-
-		*dst = '\0';
+		memcpy(dst, src, len + 1);
+		return len;
 	}
 
-	return s - src;	/* count does not include null */
+	if (0 == siz)
+		return 0;
+
+	memcpy(dst, src, siz - 1);
+	dst[siz - 1] = '\0';
+
+	return siz - 1;
 }
 
 /******************************************************************************
diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c
index cd97429e4cc..f95c1a1dd56 100644
--- a/src/libs/zbxdbcache/dbcache.c
+++ b/src/libs/zbxdbcache/dbcache.c
@@ -2900,6 +2900,8 @@ static void	sync_server_history(int *values_num, int *triggers_num, int *more)
 	zbx_vector_ptr_t		history_items, trigger_diff, item_diff, inventory_values;
 	zbx_vector_uint64_pair_t	trends_diff, proxy_subscribtions;
 	ZBX_DC_HISTORY			history[ZBX_HC_SYNC_MAX];
+	DC_ITEM				*items = NULL;
+	int				*errcodes = NULL;
 
 	item_retrieve_mode = NULL == CONFIG_EXPORT_DIR ? ZBX_ITEM_GET_SYNC : ZBX_ITEM_GET_SYNC_EXPORT;
 
@@ -2954,8 +2956,7 @@ static void	sync_server_history(int *values_num, int *triggers_num, int *more)
 
 	do
 	{
-		DC_ITEM			*items;
-		int			*errcodes, trends_num = 0, timers_num = 0, ret = SUCCEED;
+		int			trends_num = 0, timers_num = 0, ret = SUCCEED;
 		zbx_vector_uint64_t	itemids;
 		ZBX_DC_TREND		*trends = NULL;
 		zbx_timespec_t		ts;
@@ -2987,8 +2988,11 @@ static void	sync_server_history(int *values_num, int *triggers_num, int *more)
 		{
 			hc_get_item_values(history, &history_items);	/* copy item data from history cache */
 
-			items = (DC_ITEM *)zbx_malloc(NULL, sizeof(DC_ITEM) * (size_t)history_num);
-			errcodes = (int *)zbx_malloc(NULL, sizeof(int) * (size_t)history_num);
+			if (NULL == items)
+				items = (DC_ITEM *)zbx_calloc(NULL, 1, sizeof(DC_ITEM) * (size_t)ZBX_HC_SYNC_MAX);
+
+			if (NULL == errcodes)
+				errcodes = (int *)zbx_calloc(NULL, 1, sizeof(int) * (size_t)ZBX_HC_SYNC_MAX);
 
 			zbx_vector_uint64_reserve(&itemids, history_num);
 
@@ -3159,8 +3163,6 @@ static void	sync_server_history(int *values_num, int *triggers_num, int *more)
 		{
 			zbx_free(trends);
 			DCconfig_clean_items(items, errcodes, history_num);
-			zbx_free(errcodes);
-			zbx_free(items);
 
 			zbx_vector_ptr_clear(&history_items);
 			hc_free_item_values(history, history_num);
@@ -3173,6 +3175,9 @@ static void	sync_server_history(int *values_num, int *triggers_num, int *more)
 	}
 	while (ZBX_SYNC_MORE == *more && ZBX_HC_SYNC_TIME_MAX >= time(NULL) - sync_start);
 
+	zbx_free(items);
+	zbx_free(errcodes);
+
 	zbx_vector_ptr_destroy(&history_items);
 	zbx_vector_ptr_destroy(&inventory_values);
 	zbx_vector_ptr_destroy(&item_diff);
diff --git a/src/libs/zbxdbcache/dbconfig.c b/src/libs/zbxdbcache/dbconfig.c
index 040804e1991..1afe3483f10 100644
--- a/src/libs/zbxdbcache/dbconfig.c
+++ b/src/libs/zbxdbcache/dbconfig.c
@@ -7230,8 +7230,7 @@ void	DCconfig_get_items_by_itemids_partial(DC_ITEM *items, const zbx_uint64_t *i
 	const ZBX_DC_ITEM	*dc_item;
 	const ZBX_DC_HOST	*dc_host = NULL;
 
-	memset(items, 0, sizeof(DC_ITEM) * (size_t)num);
-	memset(errcodes, 0, sizeof(int) * (size_t)num);
+	memset(errcodes, 0, sizeof(int) * num);
 
 	RDLOCK_CACHE;
 
diff --git a/src/libs/zbxdbhigh/proxy.c b/src/libs/zbxdbhigh/proxy.c
index f0efb410d08..4b1e5ec9703 100644
--- a/src/libs/zbxdbhigh/proxy.c
+++ b/src/libs/zbxdbhigh/proxy.c
@@ -3476,8 +3476,8 @@ static int	process_history_data_by_itemids(zbx_socket_t *sock, zbx_client_item_v
 
 	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
 
-	items = (DC_ITEM *)zbx_malloc(NULL, sizeof(DC_ITEM) * ZBX_HISTORY_VALUES_MAX);
-	errcodes = (int *)zbx_malloc(NULL, sizeof(int) * ZBX_HISTORY_VALUES_MAX);
+	items = (DC_ITEM *)zbx_calloc(NULL, 1, sizeof(DC_ITEM) * ZBX_HISTORY_VALUES_MAX);
+	errcodes = (int *)zbx_calloc(NULL, 1, sizeof(int) * ZBX_HISTORY_VALUES_MAX);
 
 	sec = zbx_time();
 
diff --git a/src/libs/zbxserver/expression.c b/src/libs/zbxserver/expression.c
index bbdc58d97af..9f37c40d9ec 100644
--- a/src/libs/zbxserver/expression.c
+++ b/src/libs/zbxserver/expression.c
@@ -5072,8 +5072,8 @@ static void	zbx_evaluate_item_functions(zbx_hashset_t *funcs, zbx_vector_ptr_t *
 		zbx_vector_uint64_sort(&itemids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
 		zbx_vector_uint64_uniq(&itemids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
 
-		items = (DC_ITEM *)zbx_malloc(items, sizeof(DC_ITEM) * (size_t)itemids.values_num);
-		errcodes = (int *)zbx_malloc(errcodes, sizeof(int) * (size_t)itemids.values_num);
+		items = (DC_ITEM *)zbx_calloc(items, 1, sizeof(DC_ITEM) * (size_t)itemids.values_num);
+		errcodes = (int *)zbx_calloc(errcodes, 1, sizeof(int) * (size_t)itemids.values_num);
 
 		DCconfig_get_items_by_itemids_partial(items, itemids.values, errcodes, itemids.values_num,
 				ZBX_ITEM_GET_SYNC);
