Module: sip-router Branch: master Commit: 2376c833aad92bf8661f985d5917d952874a7509 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2376c833...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Mon Mar 24 22:53:22 2014 +0100
dialog: lock for updating the cseq
- race can happen on processing two requests at the same time within same dialog
---
modules/dialog/dlg_hash.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/modules/dialog/dlg_hash.c b/modules/dialog/dlg_hash.c index d8b2759..5afece8 100644 --- a/modules/dialog/dlg_hash.c +++ b/modules/dialog/dlg_hash.c @@ -585,7 +585,12 @@ int dlg_set_leg_info(struct dlg_cell *dlg, str* tag, str *rr, str *contact, * \return 0 on success, -1 on failure */ int dlg_update_cseq(struct dlg_cell * dlg, unsigned int leg, str *cseq) -{ +{ dlg_entry_t *d_entry; + + d_entry = &(d_table->entries[dlg->h_entry]); + + dlg_lock(d_table, d_entry); + if ( dlg->cseq[leg].s ) { if (dlg->cseq[leg].len < cseq->len) { shm_free(dlg->cseq[leg].s); @@ -602,9 +607,12 @@ int dlg_update_cseq(struct dlg_cell * dlg, unsigned int leg, str *cseq) memcpy( dlg->cseq[leg].s, cseq->s, cseq->len ); dlg->cseq[leg].len = cseq->len;
- LM_DBG("cseq is %.*s\n", dlg->cseq[leg].len, dlg->cseq[leg].s); + LM_DBG("cseq of leg[%d] is %.*s\n", leg, + dlg->cseq[leg].len, dlg->cseq[leg].s); + dlg_unlock(d_table, d_entry); return 0; error: + dlg_unlock(d_table, d_entry); LM_ERR("not more shm mem\n"); return -1; }