Index: apps/app_addon_sql_mysql.c =================================================================== --- apps/app_addon_sql_mysql.c (revision 1151) +++ apps/app_addon_sql_mysql.c (working copy) @@ -533,7 +533,10 @@ result = 0; if (autoclear) { - struct ast_datastore *mysql_store = ast_channel_datastore_find(chan, &mysql_ds_info, NULL); + struct ast_datastore *mysql_store = NULL; + + ast_channel_lock(chan); + mysql_store = ast_channel_datastore_find(chan, &mysql_ds_info, NULL); if (!mysql_store) { if (!(mysql_store = ast_datastore_alloc(&mysql_ds_info, NULL))) { ast_log(LOG_WARNING, "Unable to allocate new datastore.\n"); @@ -542,6 +545,7 @@ ast_channel_datastore_add(chan, mysql_store); } } + ast_channel_unlock(chan); } ast_mutex_lock(&_mysql_mutex);