OpenDDLParser: Fix another potential memory leak

pull/1498/head
Turo Lamminen 2017-11-15 12:06:21 +02:00
parent eb5f47f5c5
commit 635a515e69
1 changed files with 10 additions and 8 deletions

View File

@ -285,13 +285,15 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
} }
Property *first(ddl_nullptr); std::unique_ptr<Property> first;
in = lookForNextToken(in, end); in = lookForNextToken(in, end);
if (*in == Grammar::OpenPropertyToken[0]) { if (*in == Grammar::OpenPropertyToken[0]) {
in++; in++;
Property *prop(ddl_nullptr), *prev(ddl_nullptr); std::unique_ptr<Property> prop, prev;
while (*in != Grammar::ClosePropertyToken[0] && in != end) { while (*in != Grammar::ClosePropertyToken[0] && in != end) {
in = OpenDDLParser::parseProperty(in, end, &prop); Property *prop_(ddl_nullptr);
in = OpenDDLParser::parseProperty(in, end, &prop_);
prop.reset(prop_);
in = lookForNextToken(in, end); in = lookForNextToken(in, end);
if (*in != Grammar::CommaSeparator[0] && *in != Grammar::ClosePropertyToken[0]) { if (*in != Grammar::CommaSeparator[0] && *in != Grammar::ClosePropertyToken[0]) {
@ -301,20 +303,20 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
if (ddl_nullptr != prop && *in != Grammar::CommaSeparator[0]) { if (ddl_nullptr != prop && *in != Grammar::CommaSeparator[0]) {
if (ddl_nullptr == first) { if (ddl_nullptr == first) {
first = prop; first = std::move(prop);
} }
if (ddl_nullptr != prev) { if (ddl_nullptr != prev) {
prev->m_next = prop; prev->m_next = prop.release();
} }
prev = prop; prev = std::move(prop);
} }
} }
++in; ++in;
} }
// set the properties // set the properties
if (ddl_nullptr != first && ddl_nullptr != node) { if (first && ddl_nullptr != node) {
node->setProperties(first); node->setProperties(first.release());
} }
} }