CheckPointAgent.cpp has a noted memory leak (confirmed) and proposed optimization #232

Changed the vector to use instances of the VarNameElement instances.  Memory leak is gone.
This commit is contained in:
Alex Lin 2016-07-28 13:13:19 -05:00
parent 13b806c2f8
commit b2293a14ff
4 changed files with 21 additions and 22 deletions

View File

@ -95,7 +95,7 @@ namespace Trick {
bool reduced_checkpoint; /**< ** Reduced Checkpoint flag. */ bool reduced_checkpoint; /**< ** Reduced Checkpoint flag. */
bool hexfloat_checkpoint; /**< ** HexFloat Checkpoint flag. */ bool hexfloat_checkpoint; /**< ** HexFloat Checkpoint flag. */
int debug_level; /**< ** Debug Level. */ int debug_level; /**< ** Debug Level. */
std::vector <VarNameElement *> leftside_stack; /**< ** Left-side name stack. */ std::vector < VarNameElement > leftside_stack; /**< ** Left-side name stack. */
}; };

View File

@ -3,30 +3,30 @@
// MEMBER FUNCTION // MEMBER FUNCTION
void Trick::CheckPointAgent::push_basename( const char* name) { void Trick::CheckPointAgent::push_basename( const char* name) {
VarNameElement *part = new VarNameElement; VarNameElement part ;
part->type = BASE_NAME; part.type = BASE_NAME;
part->name = name; part.name = name;
leftside_stack.push_back( part); leftside_stack.push_back(part);
} }
// MEMBER FUNCTION // MEMBER FUNCTION
void Trick::CheckPointAgent::push_struct_elem( const char* name) { void Trick::CheckPointAgent::push_struct_elem( const char* name) {
VarNameElement *part = new VarNameElement; VarNameElement part ;
part->type = ELEM_NAME; part.type = ELEM_NAME;
part->name = name; part.name = name;
leftside_stack.push_back( part); leftside_stack.push_back( part);
} }
// MEMBER FUNCTION // MEMBER FUNCTION
void Trick::CheckPointAgent::push_array_elem( int index) { void Trick::CheckPointAgent::push_array_elem( int index) {
VarNameElement *part = new VarNameElement; VarNameElement part ;
part->type = ARRAY_INDEX; part.type = ARRAY_INDEX;
part->index = index; part.index = index;
leftside_stack.push_back( part); leftside_stack.push_back( part);
} }
@ -34,7 +34,6 @@ void Trick::CheckPointAgent::push_array_elem( int index) {
void Trick::CheckPointAgent::pop_elem() { void Trick::CheckPointAgent::pop_elem() {
leftside_stack.pop_back(); leftside_stack.pop_back();
// FIXME Memory leak here?
} }

View File

@ -75,21 +75,21 @@ std::string Trick::ClassicCheckPointAgent::left_side_name() {
for (ii = 0; ii < n_elements ; ii++) { for (ii = 0; ii < n_elements ; ii++) {
VarNameElement* element = leftside_stack[ii]; VarNameElement & element = leftside_stack[ii];
switch( element->type) { switch( element.type) {
case BASE_NAME: { case BASE_NAME: {
name = element->name; name = element.name;
} break; } break;
case ELEM_NAME: { case ELEM_NAME: {
name += '.' + element->name; name += '.' + element.name;
} break; } break;
case ARRAY_INDEX: { case ARRAY_INDEX: {
std::stringstream index_string; std::stringstream index_string;
index_string << element->index; index_string << element.index;
name += '['; name += '[';
name += index_string.str(); name += index_string.str();
name += ']'; name += ']';

View File

@ -389,21 +389,21 @@ std::string Trick::PythonPrint::left_side_name() {
for (ii = 0; ii < n_elements ; ii++) { for (ii = 0; ii < n_elements ; ii++) {
VarNameElement* element = leftside_stack[ii]; VarNameElement & element = leftside_stack[ii];
switch( element->type) { switch( element.type) {
case BASE_NAME: { case BASE_NAME: {
name = element->name; name = element.name;
} break; } break;
case ELEM_NAME: { case ELEM_NAME: {
name += '.' + element->name; name += '.' + element.name;
} break; } break;
case ARRAY_INDEX: { case ARRAY_INDEX: {
std::stringstream index_string; std::stringstream index_string;
index_string << element->index; index_string << element.index;
name += '['; name += '[';
name += index_string.str(); name += index_string.str();
name += ']'; name += ']';