Skip to content

Commit

Permalink
script routes: Fix memory corruption with dialog routes
Browse files Browse the repository at this point in the history
This patch fixes an issue which impacted the dlg_on_xxx() set of dialog
functions, where PKG and SHM memory could get mixed up when using the HA
clustering support.  The issue mostly caused the backup instance to
crash (dlg BIN receiver) instance.

(cherry picked from commit 36dbd1d)
  • Loading branch information
liviuchircu committed Dec 20, 2024
1 parent 02580bd commit 472a54f
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions route.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,30 @@ static struct script_route_ref * __ref_script_route_by_name(char *name, int l,
struct script_route_ref *ref;
unsigned int i;

/* first check if a reference to the route already exists */
for( ref=sroute_refs ; ref ; ref=ref->next ) {
if (ref->type==type && ref->name.len==l
&& strncmp(ref->name.s,name,l)==0) {
/* we found an already exists reference */
ref->u.refcnt++;
LM_DBG("returning existing %p [%.*s] with idx %d, "
"ver/cnt %d\n", ref,
ref->name.len, ref->name.s, ref->idx, ref->u.refcnt);
/* note that the returned reference may point to
* no route, there is no guarantee to be a working one */
return ref;
if (!in_shm) {
/* first check if a reference to the route already exists */
for( ref=sroute_refs ; ref ; ref=ref->next ) {
if (ref->type==type && ref->name.len==l
&& strncmp(ref->name.s,name,l)==0) {
/* we found an already exists reference */
ref->u.refcnt++;
LM_DBG("returning existing %p [%.*s] with idx %d, "
"ver/cnt %d\n", ref,
ref->name.len, ref->name.s, ref->idx, ref->u.refcnt);
/* note that the returned reference may point to
* no route, there is no guarantee to be a working one */
return ref;
}
}

/* no reference found, create a new one */
ref = pkg_malloc( sizeof *ref + l + 1 );
} else {
ref = shm_malloc( sizeof *ref + l + 1 );
}

/* no reference found, create a new one */
ref = in_shm
? shm_malloc( sizeof(struct script_route_ref) + l + 1 )
: pkg_malloc( sizeof(struct script_route_ref) + l + 1 );
if (ref==NULL) {
LM_ERR("failed to pkg allocate new sroute reference\n");
LM_ERR("failed to allocate new sroute reference\n");
return NULL;
}
ref->name.s = (char*)(ref+1);
Expand Down

0 comments on commit 472a54f

Please sign in to comment.