From ec91085765345ca840cbd409693040359cf0820b Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 20 Sep 2015 14:11:53 +0200 Subject: [PATCH] + duplicate string array for Python commands --- src/Gui/Command.cpp | 30 ++++++++++++++++++++++++++++-- src/Gui/Command.h | 9 +++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index bfcd1fff7..2cd85c39a 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -694,6 +694,12 @@ MacroCommand::MacroCommand(const char* name) eType = 0; } +MacroCommand::~MacroCommand() +{ + free(const_cast(sName)); + sName = 0; +} + void MacroCommand::activated(int iMsg) { std::string cMacroPath = App::GetApplication().GetParameterGroupByPath @@ -795,7 +801,12 @@ void MacroCommand::save() //=========================================================================== PythonCommand::PythonCommand(const char* name, PyObject * pcPyCommand, const char* pActivationString) - : Command(name),_pcPyCommand(pcPyCommand) +#if defined (_MSC_VER) + : Command( _strdup(name) ) +#else + : Command( strdup(name) ) +#endif + ,_pcPyCommand(pcPyCommand) { if (pActivationString) Activation = pActivationString; @@ -828,6 +839,14 @@ PythonCommand::PythonCommand(const char* name, PyObject * pcPyCommand, const cha } } +PythonCommand::~PythonCommand() +{ + Base::PyGILStateLocker lock; + Py_DECREF(_pcPyCommand); + free(const_cast(sName)); + sName = 0; +} + const char* PythonCommand::getResource(const char* sName) const { PyObject* pcTemp; @@ -998,7 +1017,12 @@ bool PythonCommand::isChecked() const //=========================================================================== PythonGroupCommand::PythonGroupCommand(const char* name, PyObject * pcPyCommand) - : Command(name),_pcPyCommand(pcPyCommand) +#if defined (_MSC_VER) + : Command( _strdup(name) ) +#else + : Command( strdup(name) ) +#endif + ,_pcPyCommand(pcPyCommand) { sGroup = "Python"; @@ -1032,6 +1056,8 @@ PythonGroupCommand::~PythonGroupCommand() { Base::PyGILStateLocker lock; Py_DECREF(_pcPyCommand); + free(const_cast(sName)); + sName = 0; } void PythonGroupCommand::activated(int iMsg) diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 99a669d76..119d13783 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -69,11 +69,12 @@ void CreateTestCommands(void); */ class GuiExport CommandBase { -public: +protected: CommandBase(const char* sMenu, const char* sToolTip=0, const char* sWhat=0, const char* sStatus=0, const char* sPixmap=0, const char* sAccel=0); virtual ~CommandBase(); +public: /** * Returns the Action object of this command, or 0 if it doesn't exist. */ @@ -148,7 +149,7 @@ protected: */ class GuiExport Command : public CommandBase { -public: +protected: Command(const char* name); virtual ~Command(); @@ -323,7 +324,7 @@ class PythonCommand: public Command { public: PythonCommand(const char* name, PyObject * pcPyCommand, const char* pActivationString); - virtual ~PythonCommand() {} + virtual ~PythonCommand(); protected: /** @name Methods reimplemented for Command Framework */ @@ -429,7 +430,7 @@ class MacroCommand: public Command { public: MacroCommand(const char* name); - virtual ~MacroCommand() {} + virtual ~MacroCommand(); protected: /** @name methods reimplemented for Command Framework */