diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-05-21 02:00:42 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-05-21 02:00:42 +0200 |
commit | d8df07625aec624f12377e05554387cdfeef33df (patch) | |
tree | d37b2756db5fed90410a774899f56d445a408105 /src | |
parent | 6ee9e8bf65c5b40a0265baee182369a0bf5f04df (diff) |
Fix deadlock by reference to stack local room outside the function
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Matrix.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 0577948..15a7676 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -144,34 +144,34 @@ namespace QuickMedia { } void RoomData::set_user_read_marker(std::shared_ptr<UserInfo> &user, const std::string &event_id) { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); user->read_marker_event_id = event_id; } std::string RoomData::get_user_read_marker(const std::shared_ptr<UserInfo> &user) { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); return user->read_marker_event_id; } std::string RoomData::get_user_display_name(const std::shared_ptr<UserInfo> &user) { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); return user->display_name; } std::string RoomData::get_user_avatar_url(const std::shared_ptr<UserInfo> &user) { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); return user->avatar_url; } void RoomData::set_user_display_name(std::shared_ptr<UserInfo> &user, std::string display_name) { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); user->display_name = std::move(display_name); if(user->display_name.empty()) user->display_name = user->user_id; } void RoomData::set_user_avatar_url(std::shared_ptr<UserInfo> &user, std::string avatar_url) { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); user->avatar_url = std::move(avatar_url); } @@ -218,7 +218,7 @@ namespace QuickMedia { } std::vector<std::shared_ptr<UserInfo>> RoomData::get_users() { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); std::vector<std::shared_ptr<UserInfo>> users(user_info_by_user_id.size()); size_t i = 0; for(auto &[user_id, user] : user_info_by_user_id) { @@ -228,7 +228,7 @@ namespace QuickMedia { } std::vector<std::shared_ptr<UserInfo>> RoomData::get_users_excluding_me(const std::string &my_user_id) { - std::lock_guard<std::recursive_mutex> lock(user_mutex); + std::lock_guard<std::mutex> lock(user_mutex); std::vector<std::shared_ptr<UserInfo>> users_excluding_me; for(auto &[user_id, user] : user_info_by_user_id) { if(user->user_id != my_user_id) { @@ -323,7 +323,7 @@ namespace QuickMedia { void RoomData::clear_data() { std::lock_guard<std::recursive_mutex> room_lock(room_mutex); - std::lock_guard<std::recursive_mutex> user_lock(user_mutex); + std::lock_guard<std::mutex> user_lock(user_mutex); //fetched_messages_by_event_id.clear(); //userdata = nullptr; //user_info_by_user_id.clear(); @@ -2659,17 +2659,20 @@ namespace QuickMedia { // TODO: Check this this room should be saved in the rooms list, which might be needed if the server doesn't give a non-invite events // for the same data (user display name update, etc) Invite invite; - RoomData invite_room; - events_add_user_info(events_json, &invite_room); - events_set_room_info(events_json, &invite_room); + auto invite_room = std::make_unique<RoomData>(); + RoomData *room = invite_room.get(); + invite_rooms.push_back(std::move(invite_room)); + + events_add_user_info(events_json, room); + events_set_room_info(events_json, room); std::string sender_json_str(sender_json.GetString(), sender_json.GetStringLength()); - auto invited_by = get_user_by_id(&invite_room, sender_json_str); + auto invited_by = get_user_by_id(room, sender_json_str); - set_room_info_to_users_if_empty(&invite_room, sender_json_str); + set_room_info_to_users_if_empty(room, sender_json_str); - invite.room_name = invite_room.get_name(); - invite.room_avatar_url = invite_room.get_avatar_url(); + invite.room_name = room->get_name(); + invite.room_avatar_url = room->get_avatar_url(); invite.invited_by = invited_by; invite.timestamp = timestamp_json.GetInt64(); invite.new_invite = !next_batch.empty(); |