diff --git a/src/event/server_events.c b/src/event/server_events.c index f5399ed5..eabf946b 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -646,7 +646,7 @@ sv_ev_incoming_message(ProfMessage* message) if (prefs_get_boolean(PREF_MAM)) { win_print_loading_history(window); - iq_mam_request(chatwin, g_date_time_add_seconds(message->timestamp, 0)); // copy timestamp + iq_mam_request(chatwin, g_date_time_ref(message->timestamp)); // copy timestamp } #ifdef HAVE_OMEMO diff --git a/src/otr/otr.c b/src/otr/otr.c index 5e99575a..0a67bb03 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -174,6 +174,10 @@ _otr_shutdown(void) free(jid); jid = NULL; } + if (user_state) { + otrl_userstate_free(user_state); + user_state = NULL; + } otrlib_shutdown(); } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 0d2113f0..e1cb10cf 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -173,8 +173,6 @@ create_input_window(void) char* inp_readline(void) { - free(inp_line); - inp_line = NULL; p_rl_timeout.tv_sec = inp_timeout / 1000; p_rl_timeout.tv_usec = inp_timeout % 1000 * 1000; FD_ZERO(&fds); @@ -216,7 +214,9 @@ inp_readline(void) } } } - return strdup(inp_line); + char* ret = inp_line; + inp_line = NULL; + return ret; } else { return NULL; } diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 469b03d8..344748c3 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -56,6 +56,9 @@ #include "xmpp/muc.h" static GTimer* remind_timer; +#ifdef HAVE_LIBNOTIFY +static NotifyNotification* notification; +#endif void notifier_initialise(void) @@ -67,6 +70,8 @@ void notifier_uninit(void) { #ifdef HAVE_LIBNOTIFY + g_object_unref(G_OBJECT(notification)); + notification = NULL; if (notify_is_initted()) { notify_uninit(); } @@ -208,7 +213,8 @@ notify(const char* const message, int timeout, const char* const category) notify_init("Profanity"); if (notify_is_initted()) { - NotifyNotification* notification; + if (notification) + g_object_unref(G_OBJECT(notification)); notification = notify_notification_new("Profanity", message, NULL); notify_notification_set_timeout(notification, timeout); notify_notification_set_category(notification, category); diff --git a/src/ui/tray.c b/src/ui/tray.c index a1b28692..c3ab4cf7 100644 --- a/src/ui/tray.c +++ b/src/ui/tray.c @@ -156,12 +156,15 @@ _tray_change_icon(gpointer data) static void _tray_shutdown(void) { - if (gtk_ready && prefs_get_boolean(PREF_TRAY)) { - tray_disable(); + tray_disable(); + if (icon_filename) { + g_string_free(icon_filename, TRUE); + icon_filename = NULL; + } + if (icon_msg_filename) { + g_string_free(icon_msg_filename, TRUE); + icon_msg_filename = NULL; } - g_string_free(icon_filename, TRUE); - g_string_free(icon_msg_filename, TRUE); - gtk_main_quit(); } void @@ -194,7 +197,9 @@ tray_update(void) void tray_set_timer(int interval) { - g_source_remove(timer); + if (timer) { + g_source_remove(timer); + } _tray_change_icon(NULL); timer = g_timeout_add(interval * 1000, _tray_change_icon, NULL); } @@ -219,7 +224,10 @@ void tray_disable(void) { shutting_down = TRUE; - g_source_remove(timer); + if (timer) { + g_source_remove(timer); + timer = 0; + } if (prof_tray) { g_clear_object(&prof_tray); prof_tray = NULL; diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index c211a609..7ced154b 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -169,6 +169,10 @@ connection_shutdown(void) connection_clear_data(); g_hash_table_destroy(conn.requested_features); g_hash_table_destroy(conn.available_resources); + if (conn.sm_state) { + xmpp_free_sm_state(conn.sm_state); + conn.sm_state = NULL; + } if (conn.xmpp_conn) { xmpp_conn_release(conn.xmpp_conn); conn.xmpp_conn = NULL; diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index c9f66d39..a8a485b2 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -183,7 +183,7 @@ _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const us xmpp_stanza_to_text(stanza, &text, &text_size); gboolean cont = plugins_on_iq_stanza_receive(text); xmpp_free(connection_get_ctx(), text); - if (!cont) { + if (!cont || !id_handlers) { return 1; } @@ -261,7 +261,6 @@ iq_handlers_init(void) } received_disco_items = FALSE; - iq_rooms_cache_clear(); iq_handlers_clear(); id_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_iq_id_handler_free); @@ -288,6 +287,18 @@ _win_find(char* key, } } +static void +_free_late_delivery_userdata(LateDeliveryUserdata* d) +{ + if (!d) + return; + if (d->enddate) + g_date_time_unref(d->enddate); + if (d->startdate) + g_date_time_unref(d->startdate); + free(d); +} + void iq_handlers_remove_win(ProfWin* window) { @@ -298,9 +309,11 @@ iq_handlers_remove_win(ProfWin* window) while (cur) { LateDeliveryUserdata* del_data = cur->data; next = g_slist_next(cur); - if (del_data->win == (void*)window) + if (del_data->win == (void*)window) { late_delivery_windows = g_slist_delete_link(late_delivery_windows, cur); + _free_late_delivery_userdata(del_data); + } cur = next; } struct iq_win_finder st = { 0 }; @@ -319,10 +332,15 @@ iq_handlers_remove_win(ProfWin* window) void iq_handlers_clear(void) { + iq_rooms_cache_clear(); if (id_handlers) { g_hash_table_destroy(id_handlers); id_handlers = NULL; } + if (late_delivery_windows) { + g_slist_free_full(late_delivery_windows, (GDestroyNotify)_free_late_delivery_userdata); + late_delivery_windows = NULL; + } } static void @@ -2569,8 +2587,7 @@ iq_send_stanza(xmpp_stanza_t* const stanza) if (plugin_text) { xmpp_send_raw_string(conn, "%s", plugin_text); } else { - /* libstrophe does the strlen for us, so simply always pass SIZE_MAX */ - xmpp_send_raw(conn, text, SIZE_MAX); + xmpp_send_raw(conn, text, text_size); } xmpp_free(connection_get_ctx(), text); } @@ -2716,7 +2733,7 @@ void iq_mam_request(ProfChatWin* win, GDateTime* enddate) { ProfMessage* last_msg = log_database_get_limits_info(win->barejid, TRUE); - GDateTime* startdate = g_date_time_add_seconds(last_msg->timestamp, 0); + GDateTime* startdate = g_date_time_ref(last_msg->timestamp); message_free(last_msg); // Save request for later if disco items haven't been received yet diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 5c0477b8..d9634225 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -1575,7 +1575,7 @@ _send_message_stanza(xmpp_stanza_t* const stanza) if (plugin_text) { xmpp_send_raw_string(conn, "%s", plugin_text); } else { - xmpp_send_raw_string(conn, "%s", text); + xmpp_send_raw(conn, text, text_size); } xmpp_free(connection_get_ctx(), text); } diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 62007f14..577a2e82 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -936,7 +936,7 @@ _send_presence_stanza(xmpp_stanza_t* const stanza) if (plugin_text) { xmpp_send_raw_string(conn, "%s", plugin_text); } else { - xmpp_send_raw_string(conn, "%s", text); + xmpp_send_raw(conn, text, text_size); } xmpp_free(connection_get_ctx(), text); } diff --git a/src/xmpp/session.c b/src/xmpp/session.c index 8716bb0d..75fa891a 100644 --- a/src/xmpp/session.c +++ b/src/xmpp/session.c @@ -102,6 +102,10 @@ static void _session_free_saved_details(void); static void _session_shutdown(void) { + if (reconnect_timer) { + g_timer_destroy(reconnect_timer); + reconnect_timer = NULL; + } _session_free_internals(); chat_sessions_clear(); @@ -228,7 +232,6 @@ session_disconnect(void) accounts_set_last_activity(session_get_account_name()); - iq_rooms_cache_clear(); iq_handlers_clear(); connection_disconnect();