Explorar el Código

dialog: lock for updating the cseq

- race can happen on processing two requests at the same time within
  same dialog
Daniel-Constantin Mierla hace 11 años
padre
commit
2376c833aa
Se han modificado 1 ficheros con 10 adiciones y 2 borrados
  1. 10 2
      modules/dialog/dlg_hash.c

+ 10 - 2
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;
 }