1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge pull request #1130 from profanity-im/fix/memleaks

Fix memory leaks
This commit is contained in:
Michael Vetter 2019-06-20 12:46:03 +02:00 committed by GitHub
commit 7c119aa9bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 60 additions and 13 deletions

View File

@ -305,6 +305,7 @@ omemo_on_disconnect(void)
g_key_file_free(omemo_ctx.trust_keyfile);
g_string_free(omemo_ctx.sessions_filename, TRUE);
g_key_file_free(omemo_ctx.sessions_keyfile);
_g_hash_table_free(omemo_ctx.session_store);
g_string_free(omemo_ctx.known_devices_filename, TRUE);
g_key_file_free(omemo_ctx.known_devices_keyfile);
}
@ -386,6 +387,7 @@ omemo_start_sessions(void)
const char *jid = p_contact_barejid(contact);
omemo_start_session(jid);
}
g_slist_free(contacts);
}
}

View File

@ -203,6 +203,7 @@ _create_tab(const int win, win_type_t wintype, char *identifier, gboolean highli
} else {
tab->display_name = strdup(tab->identifier);
}
prefs_free_string(pref);
}
}
@ -452,21 +453,27 @@ _status_bar_draw_maintext(int pos)
return;
}
gboolean stop = FALSE;
if (statusbar->fulljid) {
char *pref = prefs_get_string(PREF_STATUSBAR_SELF);
if (g_strcmp0(pref, "off") == 0) {
return;
}
if (g_strcmp0(pref, "user") == 0) {
stop = true;
} else if (g_strcmp0(pref, "user") == 0) {
Jid *jidp = jid_create(statusbar->fulljid);
mvwprintw(statusbar_win, 0, pos, jidp->localpart);
jid_destroy(jidp);
return;
}
if (g_strcmp0(pref, "barejid") == 0) {
stop = true;
} else if (g_strcmp0(pref, "barejid") == 0) {
Jid *jidp = jid_create(statusbar->fulljid);
mvwprintw(statusbar_win, 0, pos, jidp->barejid);
jid_destroy(jidp);
stop = true;
}
prefs_free_string(pref);
if (stop) {
return;
}
mvwprintw(statusbar_win, 0, pos, statusbar->fulljid);
@ -556,9 +563,11 @@ _display_name(StatusBarTab *tab)
} else {
fullname = strdup(tab->identifier);
}
prefs_free_string(pref);
} else if (tab->window_type == WIN_CONFIG) {
char *pref = prefs_get_string(PREF_STATUSBAR_ROOM);
GString *display_str = g_string_new("");
if (g_strcmp0("room", pref) == 0) {
Jid *jidp = jid_create(tab->identifier);
g_string_append(display_str, jidp->localpart);
@ -566,6 +575,8 @@ _display_name(StatusBarTab *tab)
} else {
g_string_append(display_str, tab->identifier);
}
prefs_free_string(pref);
g_string_append(display_str, " conf");
char *result = strdup(display_str->str);
g_string_free(display_str, TRUE);
@ -585,6 +596,7 @@ _display_name(StatusBarTab *tab)
} else {
fullname = strdup(tab->identifier);
}
prefs_free_string(pref);
} else {
fullname = strdup("window");
}

View File

@ -318,14 +318,12 @@ _bookmark_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
static void
_bookmark_destroy(Bookmark *bookmark)
{
if (!bookmark) {
return;
if (bookmark) {
free(bookmark->barejid);
free(bookmark->nick);
free(bookmark->password);
free(bookmark);
}
free(bookmark->barejid);
free(bookmark->nick);
free(bookmark->password);
free(bookmark);
}
static void

View File

@ -251,6 +251,14 @@ iq_handlers_init(void)
rooms_cache = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)xmpp_stanza_release);
}
void
iq_handlers_clear()
{
if (id_handlers) {
g_hash_table_remove_all(id_handlers);
}
}
void
iq_id_handler_add(const char *const id, ProfIqCallback func, ProfIqFreeCallback free_func, void *userdata)
{

View File

@ -178,6 +178,14 @@ message_handlers_init(void)
pubsub_event_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
}
void
message_handlers_clear(void)
{
if (pubsub_event_handlers) {
g_hash_table_remove_all(pubsub_event_handlers);
}
}
void
message_pubsub_event_handler_add(const char *const node, ProfMessageCallback func, ProfMessageFreeCallback free_func, void *userdata)
{

View File

@ -39,6 +39,7 @@ typedef int(*ProfMessageCallback)(xmpp_stanza_t *const stanza, void *const userd
typedef void(*ProfMessageFreeCallback)(void *userdata);
void message_handlers_init(void);
void message_handlers_clear(void);
void message_pubsub_event_handler_add(const char *const node, ProfMessageCallback func, ProfMessageFreeCallback free_func, void *userdata);
#endif

View File

@ -213,8 +213,10 @@ session_disconnect(void)
accounts_set_last_activity(session_get_account_name());
iq_rooms_cache_clear();
iq_handlers_clear();
connection_disconnect();
message_handlers_clear();
connection_clear_data();
chat_sessions_clear();

View File

@ -169,6 +169,7 @@ void iq_enable_carbons(void);
void iq_disable_carbons(void);
void iq_send_software_version(const char *const fulljid);
void iq_rooms_cache_clear(void);
void iq_handlers_clear();
void iq_room_list_request(gchar *conferencejid, gchar *filter);
void iq_disco_info_request(gchar *jid);
void iq_disco_items_request(gchar *jid);

View File

@ -59,6 +59,7 @@ void cmd_otr_log_on_enables_logging(void **state)
assert_true(result);
assert_string_equal("on", pref_otr_log);
prefs_free_string(pref_otr_log);
}
void cmd_otr_log_on_shows_warning_when_chlog_disabled(void **state)
@ -87,6 +88,7 @@ void cmd_otr_log_off_disables_logging(void **state)
assert_true(result);
assert_string_equal("off", pref_otr_log);
prefs_free_string(pref_otr_log);
}
void cmd_otr_redact_redacts_logging(void **state)
@ -102,6 +104,7 @@ void cmd_otr_redact_redacts_logging(void **state)
assert_true(result);
assert_string_equal("redact", pref_otr_log);
prefs_free_string(pref_otr_log);
}
void cmd_otr_log_redact_shows_warning_when_chlog_disabled(void **state)

View File

@ -67,6 +67,7 @@ void cmd_presence_console_sets_all(void **state)
assert_non_null(setting);
assert_string_equal("all", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_console_sets_online(void **state)
@ -81,6 +82,7 @@ void cmd_presence_console_sets_online(void **state)
assert_non_null(setting);
assert_string_equal("online", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_console_sets_none(void **state)
@ -95,6 +97,7 @@ void cmd_presence_console_sets_none(void **state)
assert_non_null(setting);
assert_string_equal("none", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_chat_sets_all(void **state)
@ -109,6 +112,7 @@ void cmd_presence_chat_sets_all(void **state)
assert_non_null(setting);
assert_string_equal("all", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_chat_sets_online(void **state)
@ -123,6 +127,7 @@ void cmd_presence_chat_sets_online(void **state)
assert_non_null(setting);
assert_string_equal("online", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_chat_sets_none(void **state)
@ -137,6 +142,7 @@ void cmd_presence_chat_sets_none(void **state)
assert_non_null(setting);
assert_string_equal("none", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_room_sets_all(void **state)
@ -151,6 +157,7 @@ void cmd_presence_room_sets_all(void **state)
assert_non_null(setting);
assert_string_equal("all", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_room_sets_online(void **state)
@ -165,6 +172,7 @@ void cmd_presence_room_sets_online(void **state)
assert_non_null(setting);
assert_string_equal("online", setting);
assert_true(result);
prefs_free_string(setting);
}
void cmd_presence_room_sets_none(void **state)
@ -179,4 +187,5 @@ void cmd_presence_room_sets_none(void **state)
assert_non_null(setting);
assert_string_equal("none", setting);
assert_true(result);
prefs_free_string(setting);
}

View File

@ -14,6 +14,7 @@ void statuses_console_defaults_to_all(void **state)
assert_non_null(setting);
assert_string_equal("all", setting);
prefs_free_string(setting);
}
void statuses_chat_defaults_to_all(void **state)
@ -22,6 +23,7 @@ void statuses_chat_defaults_to_all(void **state)
assert_non_null(setting);
assert_string_equal("all", setting);
prefs_free_string(setting);
}
void statuses_muc_defaults_to_all(void **state)
@ -30,4 +32,5 @@ void statuses_muc_defaults_to_all(void **state)
assert_non_null(setting);
assert_string_equal("all", setting);
prefs_free_string(setting);
}