Skip to content

Commit

Permalink
dialog: fix race due to deep copy of dlg hash table slot when saving …
Browse files Browse the repository at this point in the history
…to db

(cherry picked from commit 2d9c7f9)
  • Loading branch information
miconda committed Oct 2, 2015
1 parent 76b5d39 commit 3181001
Showing 1 changed file with 13 additions and 25 deletions.
38 changes: 13 additions & 25 deletions modules/dialog/dlg_db_handler.c
Expand Up @@ -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);
}

0 comments on commit 3181001

Please sign in to comment.