From 376cef51c494fa2e4514d757b88eec9f069445cd Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 26 Jan 2019 19:26:56 +0100 Subject: [PATCH] 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 --- dtool/src/interrogate/interfaceMakerPythonNative.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index ca2ed7eb8d..5f351dbbc1 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -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"