diff --git a/main/channel.c b/main/channel.c index 5f4676f6b7d4b5a3ca4b0d960e4d82246df9d5d2..bf35791fd0d2655a1cbd4573c386a3dfedb746d8 100644 --- a/main/channel.c +++ b/main/channel.c @@ -4835,10 +4835,14 @@ int ast_do_masquerade(struct ast_channel *original) /* Move data stores over */ if (AST_LIST_FIRST(&clonechan->datastores)) { struct ast_datastore *ds; - AST_LIST_TRAVERSE(&clonechan->datastores, ds, entry) { + /* We use a safe traversal here because some fixup routines actually + * remove the datastore from the list and free them. + */ + AST_LIST_TRAVERSE_SAFE_BEGIN(&clonechan->datastores, ds, entry) { if (ds->info->chan_fixup) ds->info->chan_fixup(ds->data, clonechan, original); } + AST_LIST_TRAVERSE_SAFE_END; AST_LIST_APPEND_LIST(&original->datastores, &clonechan->datastores, entry); }