Stack Exchange
VS2022 code analysis error C6001 Using uninitialized memory
I am getting a static code analysis

error C6001,Using uninitialized memory
'zExplicitAccess.Trustee.ptstrName'

on the following code after the VS2022(v143) upgrade. Could someone please suggest what is wrong here and how to fix it?
C++ language standard - ISO C++17 Standard

EXPLICIT_ACCESS zExplicitAccess[4];
ULONG dwIndex;

/*----- Initialize structure for new access -----*/
memset(&zExplicitAccess[0], (char)0, sizeof(EXPLICIT_ACCESS) * 4);

for (dwIndex = 0; dwIndex < 3; ++dwIndex)
  {
  zExplicitAccess[dwIndex].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  zExplicitAccess[dwIndex].Trustee.ptstrName = (char *)_GetSidFromUser(zExplicitAccess[dwIndex].Trustee.ptstrName, NULL);
  }

for (dwIndex = 0; dwIndex < 3; ++dwIndex)
  {
  free(zExplicitAccess[dwIndex].Trustee.ptstrName);// **Error 6001 here**
  }


This question's shown code fails to meet Stackoverflow's requirements for showing a [mre]. Because of that it's unlikely that anyone here can conclusively answer the question; but only guess at the most. You need to [edit] your question to show a minimal example, no more than one or two pages of code (the "minimal" part), that everyone else can cut/paste exactly as shown, compile, run, and reproduce the described issue (the "reproducible" part, this includes any ancillary information, like any input to the program). See [ask] for more information.

Hi, I 've updated the question, hopefully it's understandable now and fits the minimal criteria required

Can you answer "yes" or "no" to the following question: "Can everyone cut/paste what's shown here into an empty file; then compile, run, and reproduce the problem?" Unless your answer is "yes" how can you call this a [mre]? Go ahead: open an empty file, cut/paste exactly what's shown in this question, then try to compile that, then see what happens.

To fix the static code analysis error in VS2022, replace free with delete.
Thanks!
/*----- Convert user names to SIDS (to save time)-----*/
for (dwIndex = 0; dwIndex < 3; ++dwIndex)
  {
  zExplicitAccess[dwIndex].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  zExplicitAccess[dwIndex].Trustee.ptstrName = (char *)_GetSidFromUser(zExplicitAccess[dwIndex].Trustee.ptstrName, NULL);
  }
/*----- Tidy up SIDS -----*/
for (dwIndex = 0; dwIndex < 3; ++dwIndex)
  {
  free(zExplicitAccess[dwIndex].Trustee.ptstrName); // C6001 error
  }

