Module: kamailio
Branch: 4.3
Commit: 3181001ebae49847ed210428946fde96e89e9c4f
URL:
https://github.com/kamailio/kamailio/commit/3181001ebae49847ed210428946fde9…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2015-10-02T14:11:05+02:00
dialog: fix race due to deep copy of dlg hash table slot when saving to db
(cherry picked from commit 2d9c7f9658fe78979df69c81f56b36366b80a262)
---
Modified: modules/dialog/dlg_db_handler.c
---
Diff:
https://github.com/kamailio/kamailio/commit/3181001ebae49847ed210428946fde9…
Patch:
https://github.com/kamailio/kamailio/commit/3181001ebae49847ed210428946fde9…
---
diff --git a/modules/dialog/dlg_db_handler.c b/modules/dialog/dlg_db_handler.c
index 5dddd63..aed40e7 100644
--- a/modules/dialog/dlg_db_handler.c
+++ b/modules/dialog/dlg_db_handler.c
@@ -862,43 +862,31 @@ int update_dialog_dbinfo_unsafe(struct dlg_cell * cell)
int update_dialog_dbinfo(struct dlg_cell * cell)
{
- struct dlg_entry entry;
/* lock the entry */
- entry = (d_table->entries)[cell->h_entry];
- dlg_lock( d_table, &entry);
+ dlg_lock(d_table, &d_table->entries[cell->h_entry]);
if (update_dialog_dbinfo_unsafe(cell) != 0) {
- dlg_unlock( d_table, &entry);
+ dlg_unlock(d_table, &d_table->entries[cell->h_entry]);
return -1;
}
- dlg_unlock( d_table, &entry);
+ dlg_unlock(d_table, &d_table->entries[cell->h_entry]);
return 0;
}
void dialog_update_db(unsigned int ticks, void * param)
{
- int index;
- struct dlg_entry entry;
- struct dlg_cell * cell;
+ int i;
+ struct dlg_cell *cell;
LM_DBG("saving current_info \n");
-
- for(index = 0; index< d_table->size; index++){
- /* lock the whole entry */
- entry = (d_table->entries)[index];
- dlg_lock( d_table, &entry);
-
- for(cell = entry.first; cell != NULL; cell = cell->next){
- if (update_dialog_dbinfo_unsafe(cell) != 0) {
- dlg_unlock( d_table, &entry);
- goto error;
- }
- }
- dlg_unlock( d_table, &entry);
+ for(i = 0; i < d_table->size; i++){
+ /* lock the slot */
+ dlg_lock(d_table, &d_table->entries[i]);
+ for(cell = d_table->entries[i].first; cell != NULL; cell = cell->next){
+ /* if update fails for one dlg, still do it for the next ones */
+ update_dialog_dbinfo_unsafe(cell);
+ }
+ dlg_unlock(d_table, &d_table->entries[i]);
}
-
return;
-
-error:
- dlg_unlock( d_table, &entry);
}