1
0
mirror of https://github.com/irssi/irssi.git synced 2024-11-03 04:27:19 -05:00

Merge pull request #84 from ailin-nemui/ignore-leak

avoid memory leak in ignore cache
This commit is contained in:
ailin-nemui 2022-05-26 00:20:13 +02:00 committed by GitHub
commit af5feb16be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 9 deletions

View 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 48
#define IRSSI_ABI_VERSION 49
#define DEFAULT_SERVER_ADD_PORT 6667
#define DEFAULT_SERVER_ADD_TLS_PORT 6697

View 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();

View File

@ -28,12 +28,13 @@
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);
}

View 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.

View 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);