From 82a8c6b0c725496315e45e11ce8bcfb970c82bcf Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 6 Jul 2009 16:24:32 -0400 Subject: ENH: Exception safe link interface computation This fixes cmTarget::GetLinkInterface to compute and return the link interface in an exception-safe manner. We manage the link interface returned by cmTarget::ComputeLinkInterface using auto_ptr. --- Source/cmTarget.cxx | 17 ++++++++++------- Source/cmTarget.h | 5 ++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 6065890..3d6e1b7 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3696,19 +3696,22 @@ cmTargetLinkInterface const* cmTarget::GetLinkInterface(const char* config) if(i == this->LinkInterface.end()) { // Compute the link interface for this configuration. - cmTargetLinkInterface* iface = this->ComputeLinkInterface(config); + cmsys::auto_ptr + iface(this->ComputeLinkInterface(config)); // Store the information for this configuration. std::map::value_type - entry(config?config:"", iface); + entry(config?config:"", 0); i = this->LinkInterface.insert(entry).first; + i->second = iface.release(); } return i->second; } //---------------------------------------------------------------------------- -cmTargetLinkInterface* cmTarget::ComputeLinkInterface(const char* config) +cmsys::auto_ptr +cmTarget::ComputeLinkInterface(const char* config) { // Construct the property name suffix for this configuration. std::string suffix = "_"; @@ -3739,14 +3742,14 @@ cmTargetLinkInterface* cmTarget::ComputeLinkInterface(const char* config) // If still not set, there is no link interface. if(!libs) { - return 0; + return cmsys::auto_ptr(); } // Allocate the interface. - cmTargetLinkInterface* iface = new cmTargetLinkInterface; - if(!iface) + cmsys::auto_ptr iface(new cmTargetLinkInterface); + if(!iface.get()) { - return 0; + return cmsys::auto_ptr(); } // Expand the list of libraries in the interface. diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 12b8bb4..9e17d60 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -21,6 +21,8 @@ #include "cmPropertyMap.h" #include "cmPolicies.h" +#include + class cmake; class cmMakefile; class cmSourceFile; @@ -533,7 +535,8 @@ private: cmTargetLinkInformationMap LinkInformation; // Link interface. - cmTargetLinkInterface* ComputeLinkInterface(const char* config); + cmsys::auto_ptr + ComputeLinkInterface(const char* config); cmTargetLinkInterfaceMap LinkInterface; // The cmMakefile instance that owns this target. This should -- cgit v0.12