From 17c841c42d69987c84940232428928c39f1637cd Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 17 Jul 2013 11:02:46 -0400 Subject: [PATCH] add_custom_command: Manage backtrace memory correctly (#14299) Add an assignment operator to cmCustomCommand to copy the Backtrace member pointee and avoid multiple-free on destruction. Reported-by: Vitezslav Cizek --- Source/cmCustomCommand.cxx | 28 ++++++++++++++++++++++++++++ Source/cmCustomCommand.h | 1 + 2 files changed, 29 insertions(+) diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index bd860ee6a..3620a3895 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -13,6 +13,8 @@ #include "cmMakefile.h" +#include + //---------------------------------------------------------------------------- cmCustomCommand::cmCustomCommand() { @@ -35,6 +37,32 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r): { } +//---------------------------------------------------------------------------- +cmCustomCommand& cmCustomCommand::operator=(cmCustomCommand const& r) +{ + if(this == &r) + { + return *this; + } + + this->Outputs = r.Outputs; + this->Depends = r.Depends; + this->CommandLines = r.CommandLines; + this->HaveComment = r.HaveComment; + this->Comment = r.Comment; + this->WorkingDirectory = r.WorkingDirectory; + this->EscapeAllowMakeVars = r.EscapeAllowMakeVars; + this->EscapeOldStyle = r.EscapeOldStyle; + this->ImplicitDepends = r.ImplicitDepends; + + cmsys::auto_ptr + newBacktrace(new cmListFileBacktrace(*r.Backtrace)); + delete this->Backtrace; + this->Backtrace = newBacktrace.release(); + + return *this; +} + //---------------------------------------------------------------------------- cmCustomCommand::cmCustomCommand(cmMakefile* mf, const std::vector& outputs, diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index dd92e34d7..e20d2bf40 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -27,6 +27,7 @@ public: /** Default and copy constructors for STL containers. */ cmCustomCommand(); cmCustomCommand(const cmCustomCommand& r); + cmCustomCommand& operator=(cmCustomCommand const& r); /** Main constructor specifies all information for the command. */ cmCustomCommand(cmMakefile* mf,