Convert a crash when converting strings to QStrings to possibly a memory leak

This commit is contained in:
LostDragonist
2018-12-16 18:27:45 -06:00
parent 1bd5dda7d8
commit 4160dea823
+9 -2
View File
@@ -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<QString>*)data)->storage.bytes;
// construct QString in the allocated mr
// construct QString in the allocated memory
new (storage) QString(value);
data->convertible = storage;