Skip to content

Commit

Permalink
Fix multiple-free problem.
Browse files Browse the repository at this point in the history
Use of static constructors in headers cause the constructors/destructors to be
run in each compilation unit that includes the headers.  The multiple
constructors runs are leaks, the multiple destructor runs are multiple-frees
at program exit time.  These string constructors can instead use const char*
with little impact on the methods that reference them.
  • Loading branch information
diyessi committed Aug 3, 2015
1 parent 0dbcf94 commit 10c4802
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Common/Include/commandArgUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ namespace Microsoft { namespace MSR { namespace CNTK {
static const std::string::size_type npos = (std::string::size_type) -1;

// These are the constants associated with the "ResolveVariables" method.
static const std::string openBraceVar = "$";
static const std::string closingBraceVar = "$";
static const std::string forbiddenCharactersInVarName = ",/<>?;':\"[]{}\\|!@#%^&*()+=~` \t\n";
static const std::string forbiddenCharactersInVarNameEscapeWhitespace = ",/<>?;':\"[]{}\\|!@#%^&*()+=~` \\t\\n";
static const std::size_t openBraceVarSize = openBraceVar.size();
static const std::size_t closingBraceVarSize = openBraceVar.size();
static const char* openBraceVar = "$";
static const char* closingBraceVar = "$";
static const char* forbiddenCharactersInVarName = ",/<>?;':\"[]{}\\|!@#%^&*()+=~` \t\n";
static const char* forbiddenCharactersInVarNameEscapeWhitespace = ",/<>?;':\"[]{}\\|!@#%^&*()+=~` \\t\\n";
static const std::size_t openBraceVarSize = strlen(openBraceVar);
static const std::size_t closingBraceVarSize = strlen(closingBraceVar);

// Trim - trim white space off the start and end of the string
// str - string to trim
Expand Down Expand Up @@ -991,23 +991,23 @@ class ConfigParameters: public ConfigParser, public ConfigDictionary
while (start != std::string::npos)
{
// search for whitespace or closing brace.
end = newConfigLine.find_first_of(closingBraceVar + forbiddenCharactersInVarName,
end = newConfigLine.find_first_of(std::string(closingBraceVar) + forbiddenCharactersInVarName,
start + openBraceVarSize);

// ensure that a closing brace exists for every opening brace.
// Also ensure that there is no whitespace between the opening and closing braces.
if (end == std::string::npos)
{
RuntimeError("\"%s\" found without corresponding closing \"%s\": %s:%s",
openBraceVar.c_str(), closingBraceVar.c_str(),
openBraceVar, closingBraceVar,
m_configName.c_str(), newConfigLine.c_str());
}

if (newConfigLine[end] != '$')
{
RuntimeError("Forbidden characters found between \"%s\" and \"%s\". Variable names cannot any of the following characters: %s. %s:%s",
openBraceVar.c_str(), closingBraceVar.c_str(),
forbiddenCharactersInVarNameEscapeWhitespace.c_str(),
openBraceVar, closingBraceVar,
forbiddenCharactersInVarNameEscapeWhitespace,
m_configName.c_str(), newConfigLine.c_str());
}

Expand Down

0 comments on commit 10c4802

Please sign in to comment.