From 0c54d109cca1d3761d40adfecd629bc47619772f Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 1 Jan 2022 16:46:41 +0100 Subject: [PATCH] Fix: Do not return transient string in PyTypeManager. * Bug: In Isobar3::PyTypeManager, the accessors _getCppTypeName() and _getPyTypeName() where returning string *by value*, hence, short lived copies. But, in _setupPyType() and _addToModule(), as we interface with the Python/C API, we extract the c_str(). Which where removed as we used temporary objects. Leading to memory corruption and weird crashes. Now returns "const string&" so the c_str() stays allocated. --- .../configuration/hurricane/configuration/PyTypeManager.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hurricane/src/configuration/hurricane/configuration/PyTypeManager.h b/hurricane/src/configuration/hurricane/configuration/PyTypeManager.h index 8da5a6d3..8ee4e032 100644 --- a/hurricane/src/configuration/hurricane/configuration/PyTypeManager.h +++ b/hurricane/src/configuration/hurricane/configuration/PyTypeManager.h @@ -212,8 +212,8 @@ extern "C" { public: inline bool _isDBo () const; inline bool _isIterator () const; - inline std::string _getCppTypeName () const; - inline std::string _getPyTypeName () const; + inline const std::string& _getCppTypeName () const; + inline const std::string& _getPyTypeName () const; inline std::string _getTypeInfo () const; inline PyTypeObject* _getTypeObject (); inline PyMethodDef* _getMethods (); @@ -330,8 +330,8 @@ extern "C" { inline bool PyTypeManager::_isDBo () const { return _flags & IsDBo; } inline bool PyTypeManager::_isIterator () const { return _flags & IsIterator; } - inline std::string PyTypeManager::_getCppTypeName () const { return _cppTypeName; } - inline std::string PyTypeManager::_getPyTypeName () const { return _pyTypeName; } + inline const std::string& PyTypeManager::_getCppTypeName () const { return _cppTypeName; } + inline const std::string& PyTypeManager::_getPyTypeName () const { return _pyTypeName; } inline PyTypeObject* PyTypeManager::_getTypeObject () { return &_typeObject; } inline PyMethodDef* PyTypeManager::_getMethods () { return _methods; } inline PyGetSetDef* PyTypeManager::_getGetsets () { return _getsets; }