CertGetNameString() throws heap corruption error randomly, using the function CertGetNameStringW() does the same
LPCWSTR pszName = (LPCWSTR)malloc(cbSize * sizeof(TCHAR));
if (CertGetNameString(
pCurrentCertContext,
dwType,
dwFlags,
nullptr,
pszName,
cbSize))
{}