interrogate: fix Python 3 crash with optional std::wstring args

This would cause PyMem_Free to be called on an uninitialized pointer if a default argument was not specified.

Fixes #542
This commit is contained in:
rdb 2019-01-26 19:26:56 +01:00
parent 403e56817a
commit 376cef51c4

View File

@ -4701,7 +4701,7 @@ write_function_instance(ostream &out, FunctionRemap *remap,
if (is_optional) {
extra_convert
<< "wchar_t *" << param_name << "_str;\n"
<< "wchar_t *" << param_name << "_str = nullptr;\n"
<< "if (" << param_name << " != nullptr) {\n"
<< "#if PY_VERSION_HEX >= 0x03030000\n"
<< " " << param_name << "_str = PyUnicode_AsWideCharString(" << param_name << ", nullptr);\n"
@ -4748,7 +4748,7 @@ write_function_instance(ostream &out, FunctionRemap *remap,
if (is_optional) {
extra_convert
<< "Py_ssize_t " << param_name << "_len;\n"
<< "wchar_t *" << param_name << "_str;\n"
<< "wchar_t *" << param_name << "_str = nullptr;\n"
<< "std::wstring " << param_name << "_wstr;\n"
<< "if (" << param_name << " != nullptr) {\n"
<< "#if PY_VERSION_HEX >= 0x03030000\n"