mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Fixed memleak in chat log history
This commit is contained in:
parent
c98ce4299d
commit
186cac34de
19
src/log.c
19
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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 *);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user