"tests/pipelines/vscode:/vscode.git/clone" did not exist on "b3b2d30cd832bf205819b5d17457bf2f2182b3a7"
Commit f4b81e73 authored by jbeder's avatar jbeder
Browse files

Fixed leak when adding duplicate keys (and actually changed the behavior - now...

Fixed leak when adding duplicate keys (and actually changed the behavior - now we take the first instance, not the last)
parent 8f0f0d62
...@@ -17,7 +17,7 @@ namespace YAML ...@@ -17,7 +17,7 @@ namespace YAML
for(node_map::const_iterator it=data.begin();it!=data.end();++it) { for(node_map::const_iterator it=data.begin();it!=data.end();++it) {
std::auto_ptr<Node> pKey = it->first->Clone(); std::auto_ptr<Node> pKey = it->first->Clone();
std::auto_ptr<Node> pValue = it->second->Clone(); std::auto_ptr<Node> pValue = it->second->Clone();
m_data[pKey.release()] = pValue.release(); AddEntry(pKey, pValue);
} }
} }
...@@ -104,8 +104,7 @@ namespace YAML ...@@ -104,8 +104,7 @@ namespace YAML
pValue->Parse(pScanner, state); pValue->Parse(pScanner, state);
} }
// assign the map with the actual pointers AddEntry(pKey, pValue);
m_data[pKey.release()] = pValue.release();
} }
state.PopCollectionType(ParserState::BLOCK_MAP); state.PopCollectionType(ParserState::BLOCK_MAP);
...@@ -149,8 +148,7 @@ namespace YAML ...@@ -149,8 +148,7 @@ namespace YAML
else if(nextToken.type != Token::FLOW_MAP_END) else if(nextToken.type != Token::FLOW_MAP_END)
throw ParserException(nextToken.mark, ErrorMsg::END_OF_MAP_FLOW); throw ParserException(nextToken.mark, ErrorMsg::END_OF_MAP_FLOW);
// assign the map with the actual pointers AddEntry(pKey, pValue);
m_data[pKey.release()] = pValue.release();
} }
state.PopCollectionType(ParserState::FLOW_MAP); state.PopCollectionType(ParserState::FLOW_MAP);
...@@ -173,8 +171,7 @@ namespace YAML ...@@ -173,8 +171,7 @@ namespace YAML
pValue->Parse(pScanner, state); pValue->Parse(pScanner, state);
} }
// assign the map with the actual pointers AddEntry(pKey, pValue);
m_data[pKey.release()] = pValue.release();
state.PopCollectionType(ParserState::COMPACT_MAP); state.PopCollectionType(ParserState::COMPACT_MAP);
} }
...@@ -188,12 +185,20 @@ namespace YAML ...@@ -188,12 +185,20 @@ namespace YAML
// grab value // grab value
pScanner->pop(); pScanner->pop();
pValue->Parse(pScanner, state); pValue->Parse(pScanner, state);
// assign the map with the actual pointers AddEntry(pKey, pValue);
m_data[pKey.release()] = pValue.release();
state.PopCollectionType(ParserState::COMPACT_MAP); state.PopCollectionType(ParserState::COMPACT_MAP);
} }
void Map::AddEntry(std::auto_ptr<Node> pKey, std::auto_ptr<Node> pValue)
{
node_map::const_iterator it = m_data.find(pKey.get());
if(it != m_data.end())
return;
m_data[pKey.release()] = pValue.release();
}
void Map::Write(Emitter& out) const void Map::Write(Emitter& out) const
{ {
out << BeginMap; out << BeginMap;
......
...@@ -43,6 +43,8 @@ namespace YAML ...@@ -43,6 +43,8 @@ namespace YAML
void ParseFlow(Scanner *pScanner, ParserState& state); void ParseFlow(Scanner *pScanner, ParserState& state);
void ParseCompact(Scanner *pScanner, ParserState& state); void ParseCompact(Scanner *pScanner, ParserState& state);
void ParseCompactWithNoKey(Scanner *pScanner, ParserState& state); void ParseCompactWithNoKey(Scanner *pScanner, ParserState& state);
void AddEntry(std::auto_ptr<Node> pKey, std::auto_ptr<Node> pValue);
private: private:
node_map m_data; node_map m_data;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment