diff options
-rw-r--r-- | src/command/command.c | 1 | ||||
-rw-r--r-- | src/config/accounts.c | 61 | ||||
-rw-r--r-- | src/log.c | 5 | ||||
-rw-r--r-- | src/ui/console.c | 10 | ||||
-rw-r--r-- | src/ui/core.c | 12 | ||||
-rw-r--r-- | src/ui/statusbar.c | 16 | ||||
-rw-r--r-- | src/xmpp/capabilities.c | 9 | ||||
-rw-r--r-- | src/xmpp/iq.c | 16 | ||||
-rw-r--r-- | src/xmpp/message.c | 1 | ||||
-rw-r--r-- | src/xmpp/presence.c | 3 | ||||
-rw-r--r-- | src/xmpp/roster.c | 2 |
11 files changed, 85 insertions, 51 deletions
diff --git a/src/command/command.c b/src/command/command.c index 1032be29..41c8a2ae 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1007,6 +1007,7 @@ cmd_close(void) autocomplete_free(help_ac); autocomplete_free(notify_ac); autocomplete_free(sub_ac); + autocomplete_free(titlebar_ac); autocomplete_free(log_ac); autocomplete_free(prefs_ac); autocomplete_free(autoaway_ac); diff --git a/src/config/accounts.c b/src/config/accounts.c index c82f6b2d..3d198874 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -72,10 +72,7 @@ accounts_load(void) _fix_legacy_accounts(account_names[i]); } - for (i = 0; i < naccounts; i++) { - free(account_names[i]); - } - free(account_names); + g_strfreev(account_names); } void @@ -166,6 +163,7 @@ accounts_get_account(const char * const name) gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL); if (jid != NULL) { account->jid = strdup(jid); + g_free(jid); } else { account->jid = strdup(name); g_key_file_set_string(accounts, name, "jid", name); @@ -177,6 +175,7 @@ accounts_get_account(const char * const name) gchar *server = g_key_file_get_string(accounts, name, "server", NULL); if (server != NULL) { account->server = strdup(server); + g_free(server); } else { account->server = NULL; } @@ -184,6 +183,7 @@ accounts_get_account(const char * const name) gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL); if (resource != NULL) { account->resource = strdup(resource); + g_free(resource); } else { account->resource = NULL; } @@ -195,6 +195,10 @@ accounts_get_account(const char * const name) account->last_presence = strdup(presence); } + if (presence != NULL) { + g_free(presence); + } + presence = g_key_file_get_string(accounts, name, "presence.login", NULL); if (presence == NULL) { account->login_presence = strdup("online"); @@ -206,6 +210,10 @@ accounts_get_account(const char * const name) account->login_presence = strdup(presence); } + if (presence != NULL) { + g_free(presence); + } + account->priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL); account->priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL); account->priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL); @@ -302,7 +310,7 @@ accounts_rename(const char * const account_name, const char * const new_name) char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL); if (value != NULL) { g_key_file_set_string(accounts, new_name, string_keys[i], value); - free(value); + g_free(value); } } @@ -469,45 +477,59 @@ accounts_set_login_presence(const char * const account_name, const char * const resource_presence_t accounts_get_last_presence(const char * const account_name) { + resource_presence_t result; gchar *setting = g_key_file_get_string(accounts, account_name, "presence.last", NULL); + if (setting == NULL || (strcmp(setting, "online") == 0)) { - return RESOURCE_ONLINE; + result = RESOURCE_ONLINE; } else if (strcmp(setting, "chat") == 0) { - return RESOURCE_CHAT; + result = RESOURCE_CHAT; } else if (strcmp(setting, "away") == 0) { - return RESOURCE_AWAY; + result = RESOURCE_AWAY; } else if (strcmp(setting, "xa") == 0) { - return RESOURCE_XA; + result = RESOURCE_XA; } else if (strcmp(setting, "dnd") == 0) { - return RESOURCE_DND; + result = RESOURCE_DND; } else { log_warning("Error reading presence.last for account: '%s', value: '%s', defaulting to 'online'", account_name, setting); - return RESOURCE_ONLINE; + result = RESOURCE_ONLINE; } + + if (setting != NULL) { + g_free(setting); + } + return result; } resource_presence_t accounts_get_login_presence(const char * const account_name) { + resource_presence_t result; gchar *setting = g_key_file_get_string(accounts, account_name, "presence.login", NULL); + if (setting == NULL || (strcmp(setting, "online") == 0)) { - return RESOURCE_ONLINE; + result = RESOURCE_ONLINE; } else if (strcmp(setting, "chat") == 0) { - return RESOURCE_CHAT; + result = RESOURCE_CHAT; } else if (strcmp(setting, "away") == 0) { - return RESOURCE_AWAY; + result = RESOURCE_AWAY; } else if (strcmp(setting, "xa") == 0) { - return RESOURCE_XA; + result = RESOURCE_XA; } else if (strcmp(setting, "dnd") == 0) { - return RESOURCE_DND; + result = RESOURCE_DND; } else if (strcmp(setting, "last") == 0) { - return accounts_get_last_presence(account_name); + result = accounts_get_last_presence(account_name); } else { log_warning("Error reading presence.login for account: '%s', value: '%s', defaulting to 'online'", account_name, setting); - return RESOURCE_ONLINE; + result = RESOURCE_ONLINE; } + + if (setting != NULL) { + g_free(setting); + } + return result; } static void @@ -543,8 +565,9 @@ static void _save_accounts(void) { gsize g_data_size; - char *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL); + gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL); g_file_set_contents(accounts_loc, g_accounts_data, g_data_size, NULL); + g_free(g_accounts_data); } static gchar * diff --git a/src/log.c b/src/log.c index 7a57fa98..14d801a9 100644 --- a/src/log.c +++ b/src/log.c @@ -205,7 +205,6 @@ chat_log_init(void) void groupchat_log_init(void) { - session_started = g_date_time_new_now_local(); log_info("Initialising groupchat logs"); groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free, (GDestroyNotify)_free_chat_log); @@ -309,8 +308,6 @@ GSList * chat_log_get_previous(const gchar * const login, const gchar * const recipient, GSList *history) { - GTimeZone *tz = g_time_zone_new_local(); - GDateTime *now = g_date_time_new_now_local(); GDateTime *log_date = g_date_time_new(tz, g_date_time_get_year(session_started), @@ -349,8 +346,6 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient, log_date = g_date_time_ref(next); } - g_time_zone_unref(tz); - return history; } diff --git a/src/ui/console.c b/src/ui/console.c index 6efc1cf1..42c4e080 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -687,15 +687,15 @@ cons_show_disco_info(const char *jid, GSList *identities, GSList *features) DiscoIdentity *identity = identities->data; // anme trpe, cat GString *identity_str = g_string_new(" "); if (identity->name != NULL) { - identity_str = g_string_append(identity_str, strdup(identity->name)); + identity_str = g_string_append(identity_str, identity->name); identity_str = g_string_append(identity_str, " "); } if (identity->type != NULL) { - identity_str = g_string_append(identity_str, strdup(identity->type)); + identity_str = g_string_append(identity_str, identity->type); identity_str = g_string_append(identity_str, " "); } if (identity->category != NULL) { - identity_str = g_string_append(identity_str, strdup(identity->category)); + identity_str = g_string_append(identity_str, identity->category); } cons_show(identity_str->str); g_string_free(identity_str, FALSE); @@ -1347,7 +1347,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) title = g_string_append(title, p_contact_barejid(contact)); if (p_contact_name(contact) != NULL) { title = g_string_append(title, " ("); - title = g_string_append(title, strdup(p_contact_name(contact))); + title = g_string_append(title, p_contact_name(contact)); title = g_string_append(title, ")"); } @@ -1394,7 +1394,7 @@ _show_roster_contacts(GSList *list, gboolean show_groups) if (groups != NULL) { GString *groups_str = g_string_new(" Groups : "); while (groups != NULL) { - g_string_append(groups_str, strdup(groups->data)); + g_string_append(groups_str, groups->data); if (g_slist_next(groups) != NULL) { g_string_append(groups_str, ", "); } diff --git a/src/ui/core.c b/src/ui/core.c index b33186ec..e73c0a67 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -492,15 +492,15 @@ ui_contact_online(const char * const barejid, const char * const resource, // use nickname if exists if (p_contact_name(contact) != NULL) { - g_string_append(display_str, strdup(p_contact_name(contact))); + g_string_append(display_str, p_contact_name(contact)); } else { - g_string_append(display_str, strdup(barejid)); + g_string_append(display_str, barejid); } // add resource if not default provided by profanity if (strcmp(jid->resourcepart, "__prof_default") != 0) { g_string_append(display_str, " ("); - g_string_append(display_str, strdup(jid->resourcepart)); + g_string_append(display_str, jid->resourcepart); g_string_append(display_str, ")"); } @@ -531,15 +531,15 @@ ui_contact_offline(const char * const from, const char * const show, // use nickname if exists if (p_contact_name(contact) != NULL) { - g_string_append(display_str, strdup(p_contact_name(contact))); + g_string_append(display_str, p_contact_name(contact)); } else { - g_string_append(display_str, strdup(jidp->barejid)); + g_string_append(display_str, jidp->barejid); } // add resource if not default provided by profanity if (strcmp(jidp->resourcepart, "__prof_default") != 0) { g_string_append(display_str, " ("); - g_string_append(display_str, strdup(jidp->resourcepart)); + g_string_append(display_str, jidp->resourcepart); g_string_append(display_str, ")"); } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index cd218e73..6e7eae30 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -22,6 +22,7 @@ #include "config.h" +#include <assert.h> #include <string.h> #include <stdlib.h> @@ -63,6 +64,8 @@ create_status_bar(void) mvwprintw(status_bar, 0, cols - 31, _active); wattroff(status_bar, COLOUR_STATUS_BRACKET); + if (last_time != NULL) + g_date_time_unref(last_time); last_time = g_date_time_new_now_local(); dirty = TRUE; @@ -76,6 +79,8 @@ status_bar_refresh(void) if (elapsed >= 60000000) { dirty = TRUE; + if (last_time != NULL) + g_date_time_unref(last_time); last_time = g_date_time_new_now_local(); } @@ -113,6 +118,8 @@ status_bar_resize(void) if (message != NULL) mvwprintw(status_bar, 0, 10, message); + if (last_time != NULL) + g_date_time_unref(last_time); last_time = g_date_time_new_now_local(); dirty = TRUE; } @@ -184,13 +191,11 @@ status_bar_get_password(void) void status_bar_print_message(const char * const msg) { + werase(status_bar); + if (message != NULL) { free(message); - message = NULL; } - - werase(status_bar); - message = (char *) malloc(strlen(msg) + 1); strcpy(message, msg); mvwprintw(status_bar, 0, 10, message); @@ -270,6 +275,7 @@ static void _status_bar_update_time(void) { gchar *date_fmt = g_date_time_format(last_time, "%H:%M"); + assert(date_fmt != NULL); wattron(status_bar, COLOUR_STATUS_BRACKET); mvwaddch(status_bar, 0, 1, '['); @@ -279,7 +285,7 @@ _status_bar_update_time(void) mvwaddch(status_bar, 0, 7, ']'); wattroff(status_bar, COLOUR_STATUS_BRACKET); - free(date_fmt); + g_free(date_fmt); dirty = TRUE; } diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index ed3cf169..2b0a12e5 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -280,13 +280,14 @@ caps_create_query_response_stanza(xmpp_ctx_t * const ctx) xmpp_stanza_add_child(query, feature_version); xmpp_stanza_add_child(query, feature_ping); - xmpp_stanza_release(identity); + xmpp_stanza_release(feature_ping); + xmpp_stanza_release(feature_version); xmpp_stanza_release(feature_muc); - xmpp_stanza_release(feature_discoinfo); xmpp_stanza_release(feature_discoitems); - xmpp_stanza_release(feature_caps); - xmpp_stanza_release(feature_version); + xmpp_stanza_release(feature_discoinfo); xmpp_stanza_release(feature_chatstates); + xmpp_stanza_release(feature_caps); + xmpp_stanza_release(identity); return query; } diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 742a2258..5de84056 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -247,6 +247,12 @@ _iq_handle_version_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_send(conn, response); + g_free(version_str); + xmpp_stanza_release(name_txt); + xmpp_stanza_release(version_txt); + xmpp_stanza_release(name); + xmpp_stanza_release(version); + xmpp_stanza_release(query); xmpp_stanza_release(response); } @@ -302,6 +308,7 @@ _iq_handle_discoinfo_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_add_child(response, query); xmpp_send(conn, response); + xmpp_stanza_release(query); xmpp_stanza_release(response); } @@ -436,9 +443,6 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan log_debug("Client info not cached"); - DataForm *form = NULL; - FormField *formField = NULL; - const char *category = NULL; const char *type = NULL; const char *name = NULL; @@ -457,7 +461,8 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan xmpp_stanza_t *softwareinfo = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA); if (softwareinfo != NULL) { - form = stanza_create_form(softwareinfo); + DataForm *form = stanza_create_form(softwareinfo); + FormField *formField = NULL; if (g_strcmp0(form->form_type, STANZA_DATAFORM_SOFTWARE) == 0) { GSList *field = form->fields; @@ -477,6 +482,8 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan field = g_slist_next(field); } } + + stanza_destroy_form(form); } xmpp_stanza_t *child = xmpp_stanza_get_children(query); @@ -491,7 +498,6 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan caps_add(caps_key, category, type, name, software, software_version, os, os_version, features); - //stanza_destroy_form(form); free(caps_key); } diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 95b3152a..19b4df49 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -280,6 +280,7 @@ _groupchat_message_handler(xmpp_conn_t * const conn, message = xmpp_stanza_get_text(subject); if (message != NULL) { prof_handle_room_subject(jid->barejid, message); + xmpp_free(ctx, message); } jid_destroy(jid); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index a18bf6fe..ec439871 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -493,7 +493,7 @@ _available_handler(xmpp_conn_t * const conn, } // self presence - if (strcmp(my_jid->barejid, from_jid->barejid) ==0) { + if (strcmp(my_jid->barejid, from_jid->barejid) == 0) { connection_add_available_resource(resource); // contact presence @@ -502,6 +502,7 @@ _available_handler(xmpp_conn_t * const conn, last_activity); } + free(caps_key); free(status_str); free(show_str); jid_destroy(my_jid); diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index ed72d502..b31a2725 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -567,7 +567,7 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, while (resources != NULL) { GString *fulljid = g_string_new(strdup(barejid)); g_string_append(fulljid, "/"); - g_string_append(fulljid, strdup(resources->data)); + g_string_append(fulljid, resources->data); autocomplete_remove(fulljid_ac, fulljid->str); g_string_free(fulljid, TRUE); resources = g_list_next(resources); |