diff --git a/src/command/commands.c b/src/command/commands.c index 7b77e273..00af0df8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2790,6 +2790,7 @@ cmd_otr(gchar **args, struct cmd_help_t help) if (strcmp(args[0], "gen") == 0) { ProfAccount *account = accounts_get_account(jabber_get_account_name()); otr_keygen(account); + account_free(account); return TRUE; } else if (strcmp(args[0], "myfp") == 0) { diff --git a/src/contact.c b/src/contact.c index 52942bec..f2257b9a 100644 --- a/src/contact.c +++ b/src/contact.c @@ -223,11 +223,12 @@ _get_most_available_resource(PContact contact) // xa // dnd GList *resources = g_hash_table_get_values(contact->available_resources); - Resource *current = resources->data; + GList *curr = resources; + Resource *current = curr->data; Resource *highest = current; - resources = g_list_next(resources); - while (resources != NULL) { - current = resources->data; + curr = g_list_next(curr); + while (curr != NULL) { + current = curr->data; // priority is same as current highest, choose presence if (current->priority == highest->priority) { @@ -238,8 +239,9 @@ _get_most_available_resource(PContact contact) highest = current; } - resources = g_list_next(resources); + curr = g_list_next(curr); } + g_list_free(resources); return highest; } diff --git a/src/log.c b/src/log.c index 77ed5a6d..41ca8507 100644 --- a/src/log.c +++ b/src/log.c @@ -330,9 +330,9 @@ groupchat_log_chat(const gchar * const login, const gchar * const room, GSList * -chat_log_get_previous(const gchar * const login, const gchar * const recipient, - GSList *history) +chat_log_get_previous(const gchar * const login, const gchar * const recipient) { + GSList *history = NULL; GDateTime *now = g_date_time_new_now_local(); GDateTime *log_date = g_date_time_new(tz, g_date_time_get_year(session_started), @@ -348,14 +348,13 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient, FILE *logp = fopen(filename, "r"); if (logp != NULL) { - GString *gs_header = g_string_new(""); - g_string_append_printf(gs_header, "%d/%d/%d:", + GString *header = g_string_new(""); + g_string_append_printf(header, "%d/%d/%d:", g_date_time_get_day_of_month(log_date), g_date_time_get_month(log_date), g_date_time_get_year(log_date)); - char *header = strdup(gs_header->str); - history = g_slist_append(history, header); - g_string_free(gs_header, TRUE); + history = g_slist_append(history, header->str); + g_string_free(header, FALSE); char *line; while ((line = prof_getline(logp)) != NULL) { @@ -366,11 +365,15 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient, } free(filename); + GDateTime *next = g_date_time_add_days(log_date, 1); g_date_time_unref(log_date); - log_date = g_date_time_ref(next); + log_date = next; } + g_date_time_unref(log_date); + g_date_time_unref(now); + return history; } diff --git a/src/log.h b/src/log.h index d9cd92e1..f43b9772 100644 --- a/src/log.h +++ b/src/log.h @@ -56,7 +56,7 @@ void chat_log_chat(const gchar * const login, gchar *other, const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp); void chat_log_close(void); GSList * chat_log_get_previous(const gchar * const login, - const gchar * const recipient, GSList *history); + const gchar * const recipient); void groupchat_log_init(void); void groupchat_log_chat(const gchar * const login, const gchar * const room, diff --git a/src/main.c b/src/main.c index 33f66b04..87c25dc2 100644 --- a/src/main.c +++ b/src/main.c @@ -82,6 +82,7 @@ main(int argc, char **argv) if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print("%s\n", error->message); g_option_context_free(context); + g_error_free(error); return 1; } diff --git a/src/otr/otr.c b/src/otr/otr.c index b6b68dcd..c9280642 100644 --- a/src/otr/otr.c +++ b/src/otr/otr.c @@ -163,6 +163,14 @@ _otr_init(void) data_loaded = FALSE; } +static void +_otr_shutdown(void) +{ + if (jid != NULL) { + free(jid); + } +} + void _otr_poll(void) { @@ -172,6 +180,9 @@ _otr_poll(void) static void _otr_on_connect(ProfAccount *account) { + if (jid != NULL) { + free(jid); + } jid = strdup(account->jid); log_info("Loading OTR key for %s", jid); @@ -253,11 +264,12 @@ _otr_keygen(ProfAccount *account) return; } + if (jid != NULL) { + free(jid); + } jid = strdup(account->jid); log_info("Generating OTR key for %s", jid); - jid = strdup(account->jid); - gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); @@ -634,6 +646,7 @@ void otr_init_module(void) { otr_init = _otr_init; + otr_shutdown = _otr_shutdown; otr_libotr_version = _otr_libotr_version; otr_start_query = _otr_start_query; otr_poll = _otr_poll; diff --git a/src/otr/otr.h b/src/otr/otr.h index a8553280..0df19f42 100644 --- a/src/otr/otr.h +++ b/src/otr/otr.h @@ -41,6 +41,7 @@ OtrlMessageAppOps* otr_messageops(void); GHashTable* otr_smpinitators(void); void (*otr_init)(void); +void (*otr_shutdown)(void); char* (*otr_libotr_version)(void); char* (*otr_start_query)(void); void (*otr_poll)(void); diff --git a/src/profanity.c b/src/profanity.c index 0e69025c..013db3d8 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -311,6 +311,9 @@ _shutdown(void) muc_close(); caps_close(); ui_close(); +#ifdef HAVE_LIBOTR + otr_shutdown(); +#endif chat_log_close(); prefs_close(); theme_close(); diff --git a/src/ui/core.c b/src/ui/core.c index 62e7eec7..bb1b5887 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -138,6 +138,9 @@ _ui_get_idle_time(void) XFree(info); return result; } + if (info != NULL) { + XFree(info); + } // if no libxss or xss idle time failed, use profanity idle time #endif gdouble seconds_elapsed = g_timer_elapsed(ui_idle_time, NULL); @@ -2133,13 +2136,13 @@ _win_show_history(WINDOW *win, int win_index, const char * const contact) { ProfWin *window = wins_get_by_num(win_index); if (!window->history_shown) { - GSList *history = NULL; Jid *jid = jid_create(jabber_get_fulljid()); - history = chat_log_get_previous(jid->barejid, contact, history); + GSList *history = chat_log_get_previous(jid->barejid, contact); jid_destroy(jid); - while (history != NULL) { - wprintw(win, "%s\n", history->data); - history = g_slist_next(history); + GSList *curr = history; + while (curr != NULL) { + wprintw(win, "%s\n", curr->data); + curr = g_slist_next(curr); } window->history_shown = 1; diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index cc884e29..1add988e 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -166,8 +166,10 @@ _title_bar_draw(void) // show privacy if (current_recipient != NULL) { char *recipient_jid = NULL; - if (roster_find_contact(current_recipient) != NULL) { + char *found_contact = roster_find_contact(current_recipient); + if (found_contact != NULL) { recipient_jid = roster_barejid_from_name(current_recipient); + free(found_contact); } else { recipient_jid = current_recipient; } diff --git a/tests/log/mock_log.c b/tests/log/mock_log.c index d423b5bb..8ace164a 100644 --- a/tests/log/mock_log.c +++ b/tests/log/mock_log.c @@ -54,7 +54,7 @@ void chat_log_chat(const gchar * const login, gchar *other, const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) {} void chat_log_close(void) {} GSList * chat_log_get_previous(const gchar * const login, - const gchar * const recipient, GSList *history) + const gchar * const recipient) { return mock_ptr_type(GSList *); }