1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Merge pull request #1278 from profanity-im/memleaks

Fix few memory leaks
This commit is contained in:
Michael Vetter 2020-02-27 16:02:15 +01:00 committed by GitHub
commit 16f5106f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 6 deletions

View File

@ -80,7 +80,7 @@ static const char* _get_key(preference_t pref);
static gboolean _get_default_boolean(preference_t pref);
static char* _get_default_string(preference_t pref);
void _prefs_load(void)
static void _prefs_load(void)
{
GError *err = NULL;
log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
@ -166,9 +166,23 @@ void _prefs_load(void)
g_strfreev(triggers);
}
/* Clean up after _prefs_load() */
static void _prefs_close(void)
{
autocomplete_free(boolean_choice_ac);
autocomplete_free(room_trigger_ac);
}
void
prefs_reload(void)
{
/*
* Current function contains copy-paste, but we wanted to avoid config_file
* manipulation from prefs_load/prefs_close
*/
_prefs_close();
g_key_file_free(prefs);
prefs = NULL;
@ -185,7 +199,7 @@ prefs_load(char *config_file)
if (config_file == NULL) {
prefs_loc = files_get_config_path(FILE_PROFRC);
} else {
prefs_loc = config_file;
prefs_loc = strdup(config_file);
}
if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
@ -207,8 +221,7 @@ prefs_save(void)
void
prefs_close(void)
{
autocomplete_free(boolean_choice_ac);
autocomplete_free(room_trigger_ac);
_prefs_close();
g_key_file_free(prefs);
prefs = NULL;

View File

@ -60,7 +60,7 @@
#include "command/cmd_defs.h"
static gboolean version = FALSE;
static char *log = "INFO";
static char *log = NULL;
static char *log_file = NULL;
static char *account_name = NULL;
static char *config_file = NULL;
@ -175,7 +175,17 @@ main(int argc, char **argv)
return 0;
}
prof_run(log, account_name, config_file, log_file);
prof_run(log ? log : "INFO", account_name, config_file, log_file);
/* Free resources allocated by GOptionContext */
if (log)
g_free(log);
if (account_name)
g_free(account_name);
if (config_file)
g_free(config_file);
if (log_file)
g_free(log_file);
return 0;
}

View File

@ -252,6 +252,7 @@ iq_handlers_clear()
{
if (id_handlers) {
g_hash_table_remove_all(id_handlers);
g_hash_table_destroy(id_handlers);
id_handlers = NULL;
}
}
@ -340,6 +341,7 @@ iq_rooms_cache_clear(void)
{
if (rooms_cache) {
g_hash_table_remove_all(rooms_cache);
g_hash_table_destroy(rooms_cache);
rooms_cache = NULL;
}
}