--- asterisk-1.4.18/res/res_features.c.orig 2008-03-06 09:19:42.000000000 +0100 +++ asterisk-1.4.18/res/res_features.c 2008-03-10 16:01:03.000000000 +0100 @@ -1583,22 +1583,35 @@ bridge_cdr = ast_cdr_alloc(); if (bridge_cdr) { if (chan->cdr && peer->cdr) { /* both of them? merge */ + ast_channel_lock(chan); /* lock the channel before modifing cdrs */ ast_cdr_init(bridge_cdr,chan); /* seems more logicaller to use the destination as a base, but, really, it's random */ ast_cdr_start(bridge_cdr); /* now is the time to start */ /* absorb the channel cdr */ ast_cdr_merge(bridge_cdr, chan->cdr); - if (!ast_test_flag(chan->cdr, AST_CDR_FLAG_LOCKED)) + if (!ast_test_flag(chan->cdr, AST_CDR_FLAG_LOCKED)) ast_cdr_discard(chan->cdr); /* if locked cdrs are in chan, they are taken over in the merge */ + + chan->cdr = NULL; /* remove pointer to freed memory before releasing the lock */ + + ast_channel_unlock(chan); /* absorb the peer cdr */ + ast_channel_lock(peer); ast_cdr_merge(bridge_cdr, peer->cdr); if (!ast_test_flag(peer->cdr, AST_CDR_FLAG_LOCKED)) ast_cdr_discard(peer->cdr); /* if locked cdrs are in peer, they are taken over in the merge */ peer->cdr = NULL; + ast_channel_unlock(peer); + + ast_channel_lock(chan); chan->cdr = bridge_cdr; /* make this available to the rest of the world via the chan while the call is in progress */ + ast_channel_unlock(chan); + } else if (chan->cdr) { + + ast_channel_lock(chan); /* Lock before modifying CDR */ /* take the cdr from the channel - literally */ ast_cdr_init(bridge_cdr,chan); /* absorb this data */ @@ -1606,7 +1619,9 @@ if (!ast_test_flag(chan->cdr, AST_CDR_FLAG_LOCKED)) ast_cdr_discard(chan->cdr); /* if locked cdrs are in chan, they are taken over in the merge */ chan->cdr = bridge_cdr; /* make this available to the rest of the world via the chan while the call is in progress */ + ast_channel_unlock(chan); } else if (peer->cdr) { + ast_channel_lock(peer); /* Lock before modifying CDR */ /* take the cdr from the peer - literally */ ast_cdr_init(bridge_cdr,peer); /* absorb this data */ @@ -1615,10 +1630,13 @@ ast_cdr_discard(peer->cdr); /* if locked cdrs are in chan, they are taken over in the merge */ peer->cdr = NULL; peer->cdr = bridge_cdr; /* make this available to the rest of the world via the chan while the call is in progress */ + ast_channel_unlock(peer); } else { + ast_channel_lock(chan); /* Lock before modifying CDR */ /* make up a new cdr */ ast_cdr_init(bridge_cdr,chan); /* eh, just pick one of them */ chan->cdr = bridge_cdr; /* */ + ast_channel_unlock(chan); } if (ast_strlen_zero(bridge_cdr->dstchannel)) { if (strcmp(bridge_cdr->channel, peer->name) != 0)