mirror of
https://github.com/nasa/trick.git
synced 2024-12-20 05:37:55 +00:00
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:
parent
13b806c2f8
commit
b2293a14ff
@ -95,7 +95,7 @@ namespace Trick {
|
||||
bool reduced_checkpoint; /**< ** Reduced Checkpoint flag. */
|
||||
bool hexfloat_checkpoint; /**< ** HexFloat Checkpoint flag. */
|
||||
int debug_level; /**< ** Debug Level. */
|
||||
std::vector <VarNameElement *> leftside_stack; /**< ** Left-side name stack. */
|
||||
std::vector < VarNameElement > leftside_stack; /**< ** Left-side name stack. */
|
||||
|
||||
|
||||
};
|
||||
|
@ -3,30 +3,30 @@
|
||||
// MEMBER FUNCTION
|
||||
void Trick::CheckPointAgent::push_basename( const char* name) {
|
||||
|
||||
VarNameElement *part = new VarNameElement;
|
||||
VarNameElement part ;
|
||||
|
||||
part->type = BASE_NAME;
|
||||
part->name = name;
|
||||
leftside_stack.push_back( part);
|
||||
part.type = BASE_NAME;
|
||||
part.name = name;
|
||||
leftside_stack.push_back(part);
|
||||
}
|
||||
|
||||
// MEMBER FUNCTION
|
||||
void Trick::CheckPointAgent::push_struct_elem( const char* name) {
|
||||
|
||||
VarNameElement *part = new VarNameElement;
|
||||
VarNameElement part ;
|
||||
|
||||
part->type = ELEM_NAME;
|
||||
part->name = name;
|
||||
part.type = ELEM_NAME;
|
||||
part.name = name;
|
||||
leftside_stack.push_back( part);
|
||||
}
|
||||
|
||||
// MEMBER FUNCTION
|
||||
void Trick::CheckPointAgent::push_array_elem( int index) {
|
||||
|
||||
VarNameElement *part = new VarNameElement;
|
||||
VarNameElement part ;
|
||||
|
||||
part->type = ARRAY_INDEX;
|
||||
part->index = index;
|
||||
part.type = ARRAY_INDEX;
|
||||
part.index = index;
|
||||
leftside_stack.push_back( part);
|
||||
}
|
||||
|
||||
@ -34,7 +34,6 @@ void Trick::CheckPointAgent::push_array_elem( int index) {
|
||||
void Trick::CheckPointAgent::pop_elem() {
|
||||
|
||||
leftside_stack.pop_back();
|
||||
// FIXME Memory leak here?
|
||||
|
||||
}
|
||||
|
||||
|
@ -75,21 +75,21 @@ std::string Trick::ClassicCheckPointAgent::left_side_name() {
|
||||
|
||||
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: {
|
||||
name = element->name;
|
||||
name = element.name;
|
||||
} break;
|
||||
|
||||
case ELEM_NAME: {
|
||||
name += '.' + element->name;
|
||||
name += '.' + element.name;
|
||||
} break;
|
||||
|
||||
case ARRAY_INDEX: {
|
||||
std::stringstream index_string;
|
||||
index_string << element->index;
|
||||
index_string << element.index;
|
||||
name += '[';
|
||||
name += index_string.str();
|
||||
name += ']';
|
||||
|
@ -389,21 +389,21 @@ std::string Trick::PythonPrint::left_side_name() {
|
||||
|
||||
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: {
|
||||
name = element->name;
|
||||
name = element.name;
|
||||
} break;
|
||||
|
||||
case ELEM_NAME: {
|
||||
name += '.' + element->name;
|
||||
name += '.' + element.name;
|
||||
} break;
|
||||
|
||||
case ARRAY_INDEX: {
|
||||
std::stringstream index_string;
|
||||
index_string << element->index;
|
||||
index_string << element.index;
|
||||
name += '[';
|
||||
name += index_string.str();
|
||||
name += ']';
|
||||
|
Loading…
Reference in New Issue
Block a user