From 247c2877a832c84de0d1af547dd5350b2bddf9f3 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 26 Feb 2018 16:53:33 +0100 Subject: [PATCH] Copy callbacks list before iterating over it and calling each callbacks so we can remove a callback inside a callback call --- src/c-wrapper/api/c-chat-room.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index a8ae7b5df..12a989a58 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -430,12 +430,14 @@ const bctbx_list_t *linphone_chat_room_get_callbacks_list(const LinphoneChatRoom LinphoneChatRoomCbs ## cbName ## Cb cb = linphone_chat_room_cbs_get_ ## functionName (cr->cbs); \ if (cb) \ cb(__VA_ARGS__); \ - for (bctbx_list_t *it = cr->callbacks; it; it = bctbx_list_next(it)) { \ + bctbx_list_t *callbacks_copy = bctbx_list_copy(cr->callbacks); \ + for (bctbx_list_t *it = callbacks_copy; it; it = bctbx_list_next(it)) { \ cr->currentCbs = reinterpret_cast(bctbx_list_get_data(it)); \ cb = linphone_chat_room_cbs_get_ ## functionName (cr->currentCbs); \ if (cb) \ cb(__VA_ARGS__); \ - } + } \ + bctbx_free(callbacks_copy); void linphone_chat_room_notify_is_composing_received(LinphoneChatRoom *cr, const LinphoneAddress *remoteAddr, bool_t isComposing) { NOTIFY_IF_EXIST(IsComposingReceived, is_composing_received, cr, remoteAddr, isComposing)