Skip to content

Commit 2bc77a5

Browse files
authored
Merge pull request #3513 from vladpaiu/fix_ebr_infinit_loop
Fix infinite loop in case of errors or when skipping sub
2 parents 75ba5c2 + a9e8b92 commit 2bc77a5

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

modules/event_routing/ebr_data.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,8 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
475475

476476
/* check the EBR subscription on this event and apply the filters */
477477
sub_prev = NULL;
478-
sub_next = NULL;
479-
for ( sub=ev->subs ; sub ; sub_prev=sub,
480-
sub=sub_next?sub_next:(sub?sub->next:NULL) ) {
478+
for ( sub=ev->subs ; sub ; sub_prev=sub, sub=sub_next) {
479+
sub_next = sub->next;
481480

482481
/* discard expired subscriptions */
483482
if (sub->expire<my_time) {
@@ -507,8 +506,7 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
507506
continue; /* keep it and try next time */
508507
}
509508
}
510-
/* remove the subscription */
511-
sub_next = sub->next;
509+
512510
/* unlink it */
513511
if (sub_prev) sub_prev->next = sub_next;
514512
else ev->subs = sub_next;
@@ -521,7 +519,6 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
521519

522520
/* run the filters */
523521
matches = 1;
524-
sub_next = NULL;
525522
for ( filter=sub->filters ; matches && filter ; filter=filter->next ) {
526523

527524
/* look for the evi param with the same name */
@@ -592,9 +589,7 @@ int notify_ebr_subscriptions( ebr_event *ev, evi_params_t *params)
592589
LM_ERR("failed to send job via IPC, skipping...\n");
593590
shm_free(job);
594591
}
595-
/* remove the subscription, as it can be triggered only
596-
* one time */
597-
sub_next = sub->next;
592+
598593
/* unlink it */
599594
if (sub_prev) sub_prev->next = sub_next;
600595
else ev->subs = sub_next;
@@ -648,9 +643,8 @@ void ebr_timeout(unsigned int ticks, void* param)
648643

649644
/* check the EBR subscriptions on this event */
650645
sub_prev = NULL;
651-
sub_next = NULL;
652-
for ( sub=ev->subs ; sub ; sub_prev=sub,
653-
sub=sub_next?sub_next:(sub?sub->next:NULL) ) {
646+
for ( sub=ev->subs ; sub ; sub_prev=sub, sub=sub_next ) {
647+
sub_next = sub->next;
654648

655649
/* skip valid and non WAIT subscriptions */
656650
if ( (sub->flags&EBR_SUBS_TYPE_WAIT)==0 || sub->expire>my_time )
@@ -682,8 +676,6 @@ void ebr_timeout(unsigned int ticks, void* param)
682676
continue; /* with the next subscription */
683677
}
684678

685-
/* remove the subscription */
686-
sub_next = sub->next;
687679
/* unlink it */
688680
if (sub_prev) sub_prev->next = sub_next;
689681
else ev->subs = sub_next;

0 commit comments

Comments
 (0)