From 25b274b8d1b322121edcfa4bf4cff6f03b9c820e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Sep 2013 01:05:07 +0100 Subject: Fixed memory leaks in chat logs issue #226 --- src/log.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/log.c') diff --git a/src/log.c b/src/log.c index 14d801a9..5a278872 100644 --- a/src/log.c +++ b/src/log.c @@ -214,18 +214,17 @@ void chat_log_chat(const gchar * const login, gchar *other, const gchar * const msg, chat_log_direction_t direction, GTimeVal *tv_stamp) { - gchar *other_copy = strdup(other); - struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other_copy); + struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other); // no log for user if (dated_log == NULL) { - dated_log = _create_log(other_copy, login); - g_hash_table_insert(logs, other_copy, dated_log); + dated_log = _create_log(other, login); + g_hash_table_insert(logs, strdup(other), dated_log); // log exists but needs rolling } else if (_log_roll_needed(dated_log)) { - dated_log = _create_log(other_copy, login); - g_hash_table_replace(logs, other_copy, dated_log); + dated_log = _create_log(other, login); + g_hash_table_replace(logs, strdup(other), dated_log); } gchar *date_fmt = NULL; @@ -242,9 +241,9 @@ chat_log_chat(const gchar * const login, gchar *other, if (direction == PROF_IN_LOG) { if (strncmp(msg, "/me ", 4) == 0) { - fprintf(logp, "%s - *%s %s\n", date_fmt, other_copy, msg + 4); + fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4); } else { - fprintf(logp, "%s - %s: %s\n", date_fmt, other_copy, msg); + fprintf(logp, "%s - %s: %s\n", date_fmt, other, msg); } } else { if (strncmp(msg, "/me ", 4) == 0) { @@ -413,8 +412,8 @@ _free_chat_log(struct dated_chat_log *dated_log) g_date_time_unref(dated_log->date); dated_log->date = NULL; } + free(dated_log); } - dated_log = NULL; } static @@ -450,6 +449,7 @@ _get_log_filename(const char * const other, const char * const login, gchar *date = g_date_time_format(dt, "/%Y_%m_%d.log"); g_string_append(log_file, date); + g_free(date); char *result = strdup(log_file->str); g_string_free(log_file, TRUE); -- cgit 1.4.1-2-gfad0 f='/akkartik/mu/blame/?h=main&id=2d4c3296d8aec3d8ec6dbc83bdc59f2f8c2fad04'>root/new_lesson
blob: 3642b8233c22ca952693006ddd2ae4cd6f491aea (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12