sm00th / bitlbee-discord

Bitlbee plugin for Discord (http://discordapp.com)
GNU General Public License v2.0
291 stars 27 forks source link

Fix crash when deleting a channel #146

Closed Alcaro closed 6 years ago

Alcaro commented 6 years ago

To reproduce:

Expected: I don't see that channel again

Actual:

[22:56:27] <<< (Alcaro) discord_parse_message 274
{"t":"PRESENCE_UPDATE","s":47,"op":0,"d":{"user":{"id":"313409368643338251"},"status":"online","roles":["280006158192869376","308737073496719362"],"nick":null,"guild_id":"161245277179609089","game":{"type":0,"timestamps":{"start":1524430585163},"name":"Warframe Launcher"}}}

Program received signal SIGSEGV, Segmentation fault.
0x00005555555700e9 in irc_channel_add_user ()
(gdb) bt
#0  0x00005555555700e9 in irc_channel_add_user ()
#1  0x000055555556cc5f in ?? ()
#2  0x0000555555587a74 in imcb_chat_add_buddy ()
#3  0x00007ffff478c05d in discord_handle_presence (ic=0x555555804c50, 
    pinfo=<optimized out>, server_id=<optimized out>) at discord-handlers.c:108
#4  0x00007ffff478ddb2 in discord_parse_message (ic=ic@entry=0x555555804c50, 
    buf=buf@entry=0x555555804f70 "{\"t\":\"PRESENCE_UPDATE\",\"s\":47,\"op\":0,\"d\":{\"user\":{\"id\":\"313409368643338251\"},\"status\":\"online\",\"roles\":[\"280006158192869376\",\"308737073496719362\"],\"nick\":null,\"guild_id\":\"161245277179609089\",\"game\":{\""..., size=size@entry=274)
    at discord-handlers.c:940
#5  0x00007ffff47906e9 in discord_ws_in_cb (data=0x555555804c50, source=12, 
    cond=B_EV_IO_READ) at discord-websockets.c:281
#6  0x000055555557cfd1 in ?? ()
#7  0x00007ffff73845a0 in event_base_loop ()
   from /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5
#8  0x000055555557cb50 in b_main_run ()
#9  0x0000555555566d3d in main ()
(gdb) 

(plus 99% chance Valgrind would post a dozen use-after-free notices before that)

and bitlbee crashes before saving the new config, so I'm rejoined to the channel when bitlbee restarts.

Alcaro commented 6 years ago

It's better than crashing.

But yeah, no real point switching from broken to half-broken when a proper fix is available.

I'm not completely sure how bitlbee memory management works, but if free_channel_info deletes the gc, it's probably not a double free to delete it here.