Skip to content
Permalink
Browse files

Added support to free the scripting routes.

NOTE: things related to fixups or attached var specs are not yet freed.
  • Loading branch information
bogdan-iancu committed Mar 15, 2019
1 parent cb12ef1 commit d84cbbdafb28aacde01ee4d6b410e602e1ab82b6
Showing with 104 additions and 0 deletions.
  1. +1 −0 main.c
  2. +40 −0 route.c
  3. +2 −0 route.h
  4. +60 −0 route_struct.c
  5. +1 −0 route_struct.h
1 main.c
@@ -342,6 +342,7 @@ void cleanup(int show_status)
tr_free_extra_list();
destroy_argv_list();
destroy_black_lists();
free_route_lists(sroutes); // this is just for testing purposes
#ifdef PKG_MALLOC
if (show_status){
LM_GEN1(memdump, "Memory status (pkg):\n");
40 route.c
@@ -101,6 +101,46 @@ int init_route_lists(void)
}


void free_route_lists(struct os_script_routes *sr)
{
int i;

for( i=0 ; i<RT_NO ; i++ )
if (sr->request[i].a)
free_action_list(sr->request[i].a);

for( i=0 ; i<ONREPLY_RT_NO ; i++ )
if (sr->onreply[i].a)
free_action_list(sr->onreply[i].a);

for( i=0 ; i<FAILURE_RT_NO ; i++ )
if (sr->failure[i].a)
free_action_list(sr->failure[i].a);

for( i=0 ; i<BRANCH_RT_NO ; i++ )
if (sr->branch[i].a)
free_action_list(sr->branch[i].a);

if (sr->local.a)
free_action_list(sr->local.a);

if (sr->error.a)
free_action_list(sr->error.a);

if (sr->startup.a)
free_action_list(sr->startup.a);

for( i=0 ; i<TIMER_RT_NO ; i++ )
if (sr->timer[i].a)
free_action_list(sr->timer[i].a);

for( i=0 ; i<EVENT_RT_NO ; i++ )
if (sr->event[i].a)
free_action_list(sr->event[i].a);

}


int get_script_route_idx( char* name,struct script_route *sr, int size,int set)
{
unsigned int i;
@@ -113,6 +113,8 @@ extern int route_type;

int init_route_lists();

void free_route_lists(struct os_script_routes *sr);

int get_script_route_idx( char* name, struct script_route *sr,
int size, int set);

@@ -140,6 +140,66 @@ struct action* append_action(struct action* a, struct action* b)
}


static void free_expr( struct expr *e)
{
if (e==NULL)
return;

if (e->type==ELEM_T) {

/* left ... */
if (e->left.type==EXPR_O)
free_expr( e->left.v.expr );
else if (e->right.type==ACTION_O)
free_action_list( (struct action*)e->right.v.data );
/* ... and right */
if (e->right.type==EXPR_ST)
free_expr( e->right.v.expr );
else if (e->right.type==ACTIONS_ST)
free_action_list( (struct action*)e->right.v.data );

} else if (e->type==EXP_T) {

/* left ... */
if (e->left.v.expr)
free_expr( e->left.v.expr );
/* ... and right */
if (e->right.v.expr)
free_expr( e->right.v.expr );

}

pkg_free( e );
}


static void free_action_elem( action_elem_t *e )
{
if (e->type==EXPR_ST)
free_expr( (struct expr*)e->u.data );
else if (e->type==ACTIONS_ST)
free_action_list( (struct action*)e->u.data );
}


void free_action_list( struct action *a)
{
int i;

if (a==NULL)
return;

for( i=0 ; i<MAX_ACTION_ELEMS ; i++)
if (a->elem[i].type)
free_action_elem( &a->elem[i] );

if (a->next)
free_action_list(a->next);

pkg_free(a);
}



void print_expr(struct expr* exp)
{
@@ -149,6 +149,7 @@ struct expr* mk_elem(int op, int leftt, void *leftd, int rightt, void *rightd);
struct action* mk_action(int type, int n, action_elem_t *elem,
int line, char *file);
struct action* append_action(struct action* a, struct action* b);
void free_action_list( struct action *a);


void print_action(struct action* a);

0 comments on commit d84cbbd

Please sign in to comment.
You can’t perform that action at this time.