]> jfr.im git - irc/irssi/irssi.git/commitdiff
Merge pull request #84 from ailin-nemui/ignore-leak
authorailin-nemui <redacted>
Wed, 25 May 2022 22:20:13 +0000 (00:20 +0200)
committerAilin Nemui <redacted>
Sun, 29 May 2022 18:44:18 +0000 (20:44 +0200)
avoid memory leak in ignore cache

(cherry picked from commit af5feb16be3390340434f5c1838684c3bd9eb91a)

src/common.h
src/core/ignore.c
src/core/nickmatch-cache.c
src/core/nickmatch-cache.h
src/fe-common/core/hilight-text.c

index ad5c88bb198522717759e00512e97fc97dbac4d8..7271c14992ac36241869949c9eea975dc0dcc85b 100644 (file)
@@ -6,7 +6,7 @@
 #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
 #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
 
-#define IRSSI_ABI_VERSION 45
+#define IRSSI_ABI_VERSION 46
 
 #define DEFAULT_SERVER_ADD_PORT 6667
 #define DEFAULT_SERVER_ADD_TLS_PORT 6697
index 0bc12ed3d0d8e1fac1a8e596b4aa73cb57d9c7f2..da892c1e08ffd52a6389b82998ca3360ade7d671 100644 (file)
@@ -490,6 +490,11 @@ static void read_ignores(void)
        nickmatch_rebuild(nickmatch);
 }
 
+static void free_cache_matches(GSList *matches)
+{
+       g_slist_free(matches);
+}
+
 static void ignore_nick_cache(GHashTable *list, CHANNEL_REC *channel,
                              NICK_REC *nick)
 {
@@ -520,7 +525,7 @@ static void ignore_nick_cache(GHashTable *list, CHANNEL_REC *channel,
 void ignore_init(void)
 {
        ignores = NULL;
-       nickmatch = nickmatch_init(ignore_nick_cache);
+       nickmatch = nickmatch_init(ignore_nick_cache, (GDestroyNotify) free_cache_matches);
        time_tag = g_timeout_add(1000, (GSourceFunc) unignore_timeout, NULL);
 
         read_ignores();
index cae6620da720082feda689a389bb77e402e5e943..c8fc1157b15f4502cfd23047e95fd7ec42f6546d 100644 (file)
 
 static GSList *lists;
 
-NICKMATCH_REC *nickmatch_init(NICKMATCH_REBUILD_FUNC func)
+NICKMATCH_REC *nickmatch_init(NICKMATCH_REBUILD_FUNC func, GDestroyNotify value_destroy_func)
 {
        NICKMATCH_REC *rec;
 
        rec = g_new0(NICKMATCH_REC, 1);
        rec->func = func;
+       rec->value_destroy_func = value_destroy_func;
 
        lists = g_slist_append(lists, rec);
         return rec;
@@ -43,8 +44,9 @@ void nickmatch_deinit(NICKMATCH_REC *rec)
 {
        lists = g_slist_remove(lists, rec);
 
-        g_hash_table_destroy(rec->nicks);
-        g_free(rec);
+       if (rec->nicks != NULL)
+               g_hash_table_destroy(rec->nicks);
+       g_free(rec);
 }
 
 static void nickmatch_check_channel(CHANNEL_REC *channel, NICKMATCH_REC *rec)
@@ -65,8 +67,8 @@ void nickmatch_rebuild(NICKMATCH_REC *rec)
        if (rec->nicks != NULL)
                g_hash_table_destroy(rec->nicks);
 
-       rec->nicks = g_hash_table_new((GHashFunc) g_direct_hash,
-                                     (GCompareFunc) g_direct_equal);
+       rec->nicks = g_hash_table_new_full((GHashFunc) g_direct_hash, (GCompareFunc) g_direct_equal,
+                                          NULL, (GDestroyNotify) rec->value_destroy_func);
 
        g_slist_foreach(channels, (GFunc) nickmatch_check_channel, rec);
 }
index ff58d8530ee95df5ebf68d010aea034276038f2e..bae99c1d84b2569bb1fa08aff49daf12264b65da 100644 (file)
@@ -7,9 +7,10 @@ typedef void (*NICKMATCH_REBUILD_FUNC) (GHashTable *list,
 typedef struct {
         GHashTable *nicks;
        NICKMATCH_REBUILD_FUNC func;
+       GDestroyNotify value_destroy_func;
 } NICKMATCH_REC;
 
-NICKMATCH_REC *nickmatch_init(NICKMATCH_REBUILD_FUNC func);
+NICKMATCH_REC *nickmatch_init(NICKMATCH_REBUILD_FUNC func, GDestroyNotify value_destroy_func);
 void nickmatch_deinit(NICKMATCH_REC *rec);
 
 /* Calls rebuild function for all nicks in all channels.
index d308bd04e1a82cb9f1826bd71b9e9b61a797a26b..66e2dfd3cb4ca6a0fb27c7d2aeb80434a9ebbf26 100644 (file)
@@ -793,7 +793,7 @@ void hilight_text_init(void)
 
        read_settings();
 
-       nickmatch = nickmatch_init(hilight_nick_cache);
+       nickmatch = nickmatch_init(hilight_nick_cache, NULL);
        read_hilight_config();
 
        signal_add_first("print text", (SIGNAL_FUNC) sig_print_text);