diff options
author | James Booth <boothj5@gmail.com> | 2014-06-27 00:38:53 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-06-27 00:38:53 +0100 |
commit | 186cac34deb9f1469d5d2719b5a5746ff26156e2 (patch) | |
tree | 885dea0b0a4afa0d2fcf9297c1bde5a7bc3c2719 | |
parent | c98ce4299de670dd5d270308bf7137ea05d9c763 (diff) | |
download | profani-tty-186cac34deb9f1469d5d2719b5a5746ff26156e2.tar.gz |
Fixed memleak in chat log history
-rw-r--r-- | src/log.c | 19 | ||||
-rw-r--r-- | src/log.h | 2 | ||||
-rw-r--r-- | src/ui/core.c | 10 | ||||
-rw-r--r-- | tests/log/mock_log.c | 2 |
4 files changed, 18 insertions, 15 deletions
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/ui/core.c b/src/ui/core.c index 254af048..262eb4d3 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -2131,13 +2131,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/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 *); } |