summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2017-10-23 12:42:37 +0200
committerLemonBoy <thatlemon@gmail.com>2018-01-07 12:36:20 +0100
commitf683e81880ac4408693582df3ec11d640684c78d (patch)
tree8d028e046079a6001c3fe71adb320de32807bcf1 /src
parent432368bdc6b941c1ff6319748b357bd5bae1bb6e (diff)
downloadirssi-f683e81880ac4408693582df3ec11d640684c78d.zip
Prevent a NULL pointer deference
Always create the cap_supported table when a CAP event is received.
Diffstat (limited to 'src')
-rw-r--r--src/irc/core/irc-cap.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/irc/core/irc-cap.c b/src/irc/core/irc-cap.c
index f448ef83..46276243 100644
--- a/src/irc/core/irc-cap.c
+++ b/src/irc/core/irc-cap.c
@@ -135,19 +135,21 @@ static void event_cap (IRC_SERVER_REC *server, char *args, char *nick, char *add
return;
}
+ /* The table is created only when needed */
+ if (server->cap_supported == NULL) {
+ server->cap_supported = g_hash_table_new_full(g_str_hash,
+ g_str_equal,
+ g_free, g_free);
+ }
+
/* Strip the trailing whitespaces before splitting the string, some servers send responses with
* superfluous whitespaces that g_strsplit the interprets as tokens */
caps = g_strsplit(g_strchomp(list), " ", -1);
caps_length = g_strv_length(caps);
if (!strcmp(evt, "LS")) {
- if (server->cap_supported) {
- g_hash_table_destroy(server->cap_supported);
- }
- /* Start with a fresh table */
- server->cap_supported = g_hash_table_new_full(g_str_hash,
- g_str_equal,
- g_free, g_free);
+ /* Throw away everything and start from scratch */
+ g_hash_table_remove_all(server->cap_supported);
/* Create a list of the supported caps */
for (i = 0; i < caps_length; i++) {