From 2d94194d450843cefb85aab3c314ef71e0a4d88c Mon Sep 17 00:00:00 2001 From: mjentsch Date: Sat, 7 Mar 2015 16:13:44 +0100 Subject: [PATCH] Fix segfault on automatic chat join Check if peer was already allocated in chat_show. The auto-join flag can be safely ignored, all incoming chat messages are added to the chat anyways and will trigger an opening of the chat. --- tgp-chat.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tgp-chat.c b/tgp-chat.c index 05ffebf..c0dd2f9 100644 --- a/tgp-chat.c +++ b/tgp-chat.c @@ -19,6 +19,7 @@ */ #include "tgp-chat.h" +#include "msglog.h" void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat) { int i; @@ -39,13 +40,18 @@ void chat_users_update (struct tgl_state *TLS, struct tgl_chat *chat) { PurpleConversation *chat_show (PurpleConnection *gc, int id) { connection_data *conn = purple_connection_get_protocol_data(gc); - PurpleConversation *convo = purple_find_chat (gc, id); + tgl_peer_t *P = tgl_peer_get (conn->TLS, TGL_MK_CHAT(id)); + if (! convo) { - tgl_peer_t *P = tgl_peer_get (conn->TLS, TGL_MK_CHAT(id)); + if (! P) { + warning ("Chat %d not existing, not showing...", id); + return NULL; + } convo = p2tgl_got_joined_chat (conn->TLS, &P->chat); chat_users_update (conn->TLS, &P->chat); } + return convo; }