2

i have the following piece of code

int nArgs;
if (LPWSTR * const szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs))
{
  PySys_SetArgvEx(nArgs, szArglist, false);
  LocalFree(szArglist);
}

I cannot find in Python documentation if memory pointed by szArglist shall be preserved until Python is shutdown or i can free it immediately.

Can anybody put some light on this, please?

Thank you! Vladimir

denfromufa
  • 5,610
  • 13
  • 81
  • 138

1 Answers1

1

The Python C API looks like it is using a new PyList object to fill out the args, and is allocating its own memory for the char* arguments.

On strings longer than 1 characters, PySys_SetArgvEx will malloc its own memory for the string.

So it's safe to delete any memory allocated that you passed to PySys_SetArgvEx.

KymikoLoco
  • 1,433
  • 1
  • 15
  • 17