From 4160dea823384d8905918fa82243575cf11ac4eb Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Sun, 16 Dec 2018 18:27:45 -0600 Subject: [PATCH] Convert a crash when converting strings to QStrings to possibly a memory leak --- src/runner/pythonrunner.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 76d31cb..f79f9dc 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -102,16 +102,23 @@ struct QString_from_python_str static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) { // Ensure the string uses 8-bit characters PyObject *strPtr = PyUnicode_Check(objPtr) ? PyUnicode_AsUTF8String(objPtr) : objPtr; + // Extract the character data from the python string const char* value = SIPBytes_AsString(strPtr); + assert(value != nullptr); + + // TODO: This sometimes causes a crash when QString is called below (error 5, access denied, etc.). + // This may cause a memory leak that'll need to be fixed at some point but the impact is fairly low. +#if false // Deallocate local copy if one was made if (strPtr != objPtr) Py_DecRef(strPtr); - assert(value != nullptr); +#endif // allocate storage void *storage = ((bpy::converter::rvalue_from_python_storage*)data)->storage.bytes; - // construct QString in the allocated mr + + // construct QString in the allocated memory new (storage) QString(value); data->convertible = storage;