Keep track of and free the reference attr created by ref_var. Refs #154

This commit is contained in:
John M. Penn 2016-03-08 17:47:09 -06:00
parent 9b652d0a11
commit ced68e24b2
7 changed files with 19 additions and 14 deletions

View File

@ -21,7 +21,6 @@ public:
int verify_input; /**< -- Verify input runstream syntax flag */
int echo_input; /**< -- OBSOLETE? Echo Initialization Data flag */
REF2 *result; /**< ** Resulting REF2 structure from the reference parser.*/
ATTRIBUTES * reference_attr ; /**< ** saved reference attr to be deleted after ref_name is called */
std::istream *is; /**< ** Input Stream.*/
void *scanner; /**< ** flex/bision scanner varaible. Magic! */
Trick::MemoryManager *mem_mgr; /**< ** Memory Manager. */

View File

@ -59,6 +59,7 @@ typedef struct {
void* address; /**< ** Address of the specified reference */
V_DATA v_data; /**< ** Value */
ATTRIBUTES* attr; /**< -- Parameter attributes */
ATTRIBUTES* ref_attr; /**< -- Dynamically allocated reference attribute. */
int create_add_path ; /**< ** bool to shortcut to resolve address */
DLLIST * address_path ; /**< ** shortcut to resolve address */
} REF2;

View File

@ -293,6 +293,13 @@ assignment: reference assignment_item ';' {
}
delete_v_tree($2);
/* If the attributes are dynamically-allocated, reference
* attributes then free them so we don't leak memory.
*/
if ($1.attr == $1.ref_attr) {
free($1.ref_attr);
$1.ref_attr = NULL;
}
}
assignment_item: v_data {

View File

@ -98,9 +98,17 @@ int Trick::MemoryManager::ref_name(REF2 * R, char *name) {
}
}
/* Save the address and next attributes in the REF structure */
/* Save the address and next attributes in the REF structure.
If the attributes are dynamically-allocated, reference attributes
then free them so we don't leak memory.
*/
if (R->attr == R->ref_attr) {
free(R->ref_attr);
R->ref_attr = NULL;
}
R->attr = attr;
R->address = addr;
return (MM_OK);
}

View File

@ -15,8 +15,9 @@ int Trick::MemoryManager::ref_var( REF2* R,
if (pos != variable_map.end()) {
alloc_info = pos->second;
R->attr = make_reference_attr( alloc_info);
R->ref_attr = R->attr;
R->address = alloc_info->start;
if ( R->create_add_path ) {
ADDRESS_NODE * address_node ;

View File

@ -9,7 +9,6 @@
// Set verif input and echo input flags.
verify_input = 0;
echo_input = 1;
reference_attr = NULL ;
// Initialize the scanner
init_scanner();

View File

@ -96,8 +96,6 @@ param: NAME {
if ((ret = context->mem_mgr->ref_var( &$$, $1)) != MM_OK) {
return ( ret);
}
// save the reference attributes allocated by ref_var so we can delete it after ref_name is called.
context->reference_attr = $$.attr ;
$$.num_index_left = $$.attr->num_index;
$$.reference = $1 ;
@ -126,8 +124,6 @@ param: NAME {
Trick::MemoryManager::emitError(message.str());
return ( ret);
}
// save the reference attributes allocated by ref_var so we can delete it after ref_name is called.
context->reference_attr = $$.attr ;
$$.num_index_left = $$.attr->num_index;
//$$.reference = strdup($2) ;
@ -168,12 +164,6 @@ param: NAME {
return (ret);
}
// free the reference attributes, ref_name overwrites $$.attr without freeing it
if ( context->reference_attr ) {
free(context->reference_attr) ;
context->reference_attr = NULL ;
}
/* create a new reference string because previous nodes may refer to old strings */
$$.num_index_left = $$.attr->num_index;