mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -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 *
|
GSList *
|
||||||
chat_log_get_previous(const gchar * const login, const gchar * const recipient,
|
chat_log_get_previous(const gchar * const login, const gchar * const recipient)
|
||||||
GSList *history)
|
|
||||||
{
|
{
|
||||||
|
GSList *history = NULL;
|
||||||
GDateTime *now = g_date_time_new_now_local();
|
GDateTime *now = g_date_time_new_now_local();
|
||||||
GDateTime *log_date = g_date_time_new(tz,
|
GDateTime *log_date = g_date_time_new(tz,
|
||||||
g_date_time_get_year(session_started),
|
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");
|
FILE *logp = fopen(filename, "r");
|
||||||
if (logp != NULL) {
|
if (logp != NULL) {
|
||||||
GString *gs_header = g_string_new("");
|
GString *header = g_string_new("");
|
||||||
g_string_append_printf(gs_header, "%d/%d/%d:",
|
g_string_append_printf(header, "%d/%d/%d:",
|
||||||
g_date_time_get_day_of_month(log_date),
|
g_date_time_get_day_of_month(log_date),
|
||||||
g_date_time_get_month(log_date),
|
g_date_time_get_month(log_date),
|
||||||
g_date_time_get_year(log_date));
|
g_date_time_get_year(log_date));
|
||||||
char *header = strdup(gs_header->str);
|
history = g_slist_append(history, header->str);
|
||||||
history = g_slist_append(history, header);
|
g_string_free(header, FALSE);
|
||||||
g_string_free(gs_header, TRUE);
|
|
||||||
|
|
||||||
char *line;
|
char *line;
|
||||||
while ((line = prof_getline(logp)) != NULL) {
|
while ((line = prof_getline(logp)) != NULL) {
|
||||||
@ -366,11 +365,15 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient,
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(filename);
|
free(filename);
|
||||||
|
|
||||||
GDateTime *next = g_date_time_add_days(log_date, 1);
|
GDateTime *next = g_date_time_add_days(log_date, 1);
|
||||||
g_date_time_unref(log_date);
|
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;
|
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);
|
const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp);
|
||||||
void chat_log_close(void);
|
void chat_log_close(void);
|
||||||
GSList * chat_log_get_previous(const gchar * const login,
|
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_init(void);
|
||||||
void groupchat_log_chat(const gchar * const login, const gchar * const room,
|
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);
|
ProfWin *window = wins_get_by_num(win_index);
|
||||||
if (!window->history_shown) {
|
if (!window->history_shown) {
|
||||||
GSList *history = NULL;
|
|
||||||
Jid *jid = jid_create(jabber_get_fulljid());
|
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);
|
jid_destroy(jid);
|
||||||
while (history != NULL) {
|
GSList *curr = history;
|
||||||
wprintw(win, "%s\n", history->data);
|
while (curr != NULL) {
|
||||||
history = g_slist_next(history);
|
wprintw(win, "%s\n", curr->data);
|
||||||
|
curr = g_slist_next(curr);
|
||||||
}
|
}
|
||||||
window->history_shown = 1;
|
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) {}
|
const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) {}
|
||||||
void chat_log_close(void) {}
|
void chat_log_close(void) {}
|
||||||
GSList * chat_log_get_previous(const gchar * const login,
|
GSList * chat_log_get_previous(const gchar * const login,
|
||||||
const gchar * const recipient, GSList *history)
|
const gchar * const recipient)
|
||||||
{
|
{
|
||||||
return mock_ptr_type(GSList *);
|
return mock_ptr_type(GSList *);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user