use xcalloc instead of xmallocz
restore for logic from patch 7.4.344