From b9d29e9aa59a16bcfc06f7e91fd562688565e12a Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Sun, 14 Jul 2013 23:58:02 +0300 Subject: draft of bookmarks implementation '/bookmark add' and '/bookmark remove' ain't finished --- src/ui/console.c | 29 +++++++++++++++++++++++++++++ src/ui/ui.h | 1 + 2 files changed, 30 insertions(+) (limited to 'src/ui') diff --git a/src/ui/console.c b/src/ui/console.c index ee5ad221..50d2b649 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -37,6 +37,7 @@ #include "ui/window.h" #include "ui/ui.h" #include "xmpp/xmpp.h" +#include "xmpp/bookmark.h" #define CONS_WIN_TITLE "_cons" @@ -643,6 +644,34 @@ cons_show_room_list(GSList *rooms, const char * const conference_node) cons_alert(); } +void +cons_show_bookmarks(const GList *list) +{ + Bookmark *item; + + cons_show(""); + cons_show("Bookmarks:"); + + /* TODO: show status (connected or not) and window number */ + while (list != NULL) { + item = list->data; + + win_print_time(console, '-'); + wprintw(console->win, " %s", item->jid); + if (item->nick != NULL) { + wprintw(console->win, "/%s", item->nick); + } + if (item->autojoin) { + wprintw(console->win, " (autojoin)"); + } + wprintw(console->win, "\n"); + list = g_list_next(list); + } + + ui_console_dirty(); + cons_alert(); +} + void cons_show_disco_info(const char *jid, GSList *identities, GSList *features) { diff --git a/src/ui/ui.h b/src/ui/ui.h index d8ac22fa..f0601753 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -184,6 +184,7 @@ void cons_show_software_version(const char * const jid, const char * const version, const char * const os); void cons_show_account_list(gchar **accounts); void cons_show_room_list(GSList *room, const char * const conference_node); +void cons_show_bookmarks(const GList *list); void cons_show_disco_items(GSList *items, const char * const jid); void cons_show_disco_info(const char *from, GSList *identities, GSList *features); void cons_show_room_invite(const char * const invitor, const char * const room, -- cgit 1.4.1-2-gfad0 From c559d96d7739d499f9b747839e1115d28976306f Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Sat, 3 Aug 2013 13:17:50 +0300 Subject: removed sizeof(char) sizeof(char) == 1 according to standard --- src/command/command.c | 2 +- src/tools/autocomplete.c | 4 ++-- src/ui/statusbar.c | 2 +- src/ui/titlebar.c | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/ui') diff --git a/src/command/command.c b/src/command/command.c index 45086e18..1017b899 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1041,7 +1041,7 @@ cmd_autocomplete(char *input, int *size) inp_cpy[i] = '\0'; found = autocomplete_complete(commands_ac, inp_cpy); if (found != NULL) { - auto_msg = (char *) malloc((strlen(found) + 1) * sizeof(char)); + auto_msg = (char *) malloc(strlen(found) + 1); strcpy(auto_msg, found); inp_replace_input(input, auto_msg, size); free(auto_msg); diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 0c56cac7..8426de85 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -220,7 +220,7 @@ autocomplete_param_with_func(char *input, int *size, char *command, inp_cpy[(*size) - len] = '\0'; found = func(inp_cpy); if (found != NULL) { - auto_msg = (char *) malloc((len + (strlen(found) + 1)) * sizeof(char)); + auto_msg = (char *) malloc(len + strlen(found) + 1); strcpy(auto_msg, command_cpy); strcat(auto_msg, found); free(found); @@ -249,7 +249,7 @@ autocomplete_param_with_ac(char *input, int *size, char *command, inp_cpy[(*size) - len] = '\0'; found = autocomplete_complete(ac, inp_cpy); if (found != NULL) { - auto_msg = (char *) malloc((len + (strlen(found) + 1)) * sizeof(char)); + auto_msg = (char *) malloc(len + strlen(found) + 1); strcpy(auto_msg, command_cpy); strcat(auto_msg, found); free(found); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 3f0798d3..cd218e73 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -191,7 +191,7 @@ status_bar_print_message(const char * const msg) werase(status_bar); - message = (char *) malloc((strlen(msg) + 1) * sizeof(char)); + message = (char *) malloc(strlen(msg) + 1); strcpy(message, msg); mvwprintw(status_bar, 0, 10, message); diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 4b3ca997..791a5fbe 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -87,7 +87,7 @@ title_bar_refresh(void) free(current_title); } - current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char)); + current_title = (char *) malloc(strlen(recipient) + 1); strcpy(current_title, recipient); title_bar_draw(); @@ -113,7 +113,7 @@ title_bar_show(const char * const title) if (current_title != NULL) free(current_title); - current_title = (char *) malloc((strlen(title) + 1) * sizeof(char)); + current_title = (char *) malloc(strlen(title) + 1); strcpy(current_title, title); _title_bar_draw_title(); } @@ -138,7 +138,7 @@ title_bar_set_recipient(const char * const from) free(current_title); } - current_title = (char *) malloc((strlen(from) + 1) * sizeof(char)); + current_title = (char *) malloc(strlen(from) + 1); strcpy(current_title, from); dirty = TRUE; @@ -160,10 +160,10 @@ title_bar_set_typing(gboolean is_typing) } if (is_typing) { - current_title = (char *) malloc((strlen(recipient) + 13) * sizeof(char)); + current_title = (char *) malloc(strlen(recipient) + 13); sprintf(current_title, "%s (typing...)", recipient); } else { - current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char)); + current_title = (char *) malloc(strlen(recipient) + 1); strcpy(current_title, recipient); } -- cgit 1.4.1-2-gfad0 From 0346fda0b3ddc484c3a28d88a5c42b890feb3079 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Sat, 3 Aug 2013 14:27:07 +0300 Subject: most FREE_SET_NULL replaced with free FREE_SET_NULL makes extra assignment of NULL for pointers in stack or dynamic memory that is going to be freed. FREE_SET_NULL is useful for pointers that can be used in future. --- src/config/accounts.c | 14 +++++++------- src/contact.c | 34 +++++++++++++++------------------- src/jid.c | 14 +++++++------- src/muc.c | 20 ++++---------------- src/resource.c | 11 ++++++----- src/tools/autocomplete.c | 6 ++---- src/ui/console.c | 2 +- src/ui/core.c | 5 +++-- src/xmpp/capabilities.c | 17 ++++++++--------- src/xmpp/presence.c | 26 +++++++++++++++----------- src/xmpp/stanza.c | 8 ++++---- 11 files changed, 72 insertions(+), 85 deletions(-) (limited to 'src/ui') diff --git a/src/config/accounts.c b/src/config/accounts.c index 876ff870..c82f6b2d 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -236,13 +236,13 @@ void accounts_free_account(ProfAccount *account) { if (account != NULL) { - FREE_SET_NULL(account->name); - FREE_SET_NULL(account->jid); - FREE_SET_NULL(account->resource); - FREE_SET_NULL(account->server); - FREE_SET_NULL(account->last_presence); - FREE_SET_NULL(account->login_presence); - FREE_SET_NULL(account); + free(account->name); + free(account->jid); + free(account->resource); + free(account->server); + free(account->last_presence); + free(account->login_presence); + free(account); } } diff --git a/src/contact.c b/src/contact.c index 44cbd4b4..1b566d40 100644 --- a/src/contact.c +++ b/src/contact.c @@ -79,14 +79,9 @@ p_contact_new(const char * const barejid, const char * const name, void p_contact_set_name(const PContact contact, const char * const name) { - if (contact->name != NULL) { - FREE_SET_NULL(contact->name); - } - + FREE_SET_NULL(contact->name); if (name != NULL) { contact->name = strdup(name); - } else { - FREE_SET_NULL(contact->name); } } @@ -130,22 +125,23 @@ p_contact_remove_resource(PContact contact, const char * const resource) void p_contact_free(PContact contact) { - FREE_SET_NULL(contact->barejid); - FREE_SET_NULL(contact->name); - FREE_SET_NULL(contact->subscription); - FREE_SET_NULL(contact->offline_message); + if (contact != NULL) { + free(contact->barejid); + free(contact->name); + free(contact->subscription); + free(contact->offline_message); + + if (contact->groups != NULL) { + g_slist_free_full(contact->groups, g_free); + } - if (contact->groups != NULL) { - g_slist_free_full(contact->groups, g_free); - } + if (contact->last_activity != NULL) { + g_date_time_unref(contact->last_activity); + } - if (contact->last_activity != NULL) { - g_date_time_unref(contact->last_activity); + g_hash_table_destroy(contact->available_resources); + free(contact); } - - g_hash_table_destroy(contact->available_resources); - - FREE_SET_NULL(contact); } const char * diff --git a/src/jid.c b/src/jid.c index b236c164..6840b64b 100644 --- a/src/jid.c +++ b/src/jid.c @@ -108,13 +108,13 @@ void jid_destroy(Jid *jid) { if (jid != NULL) { - GFREE_SET_NULL(jid->str); - GFREE_SET_NULL(jid->localpart); - GFREE_SET_NULL(jid->domainpart); - GFREE_SET_NULL(jid->resourcepart); - GFREE_SET_NULL(jid->barejid); - GFREE_SET_NULL(jid->fulljid); - FREE_SET_NULL(jid); + g_free(jid->str); + g_free(jid->localpart); + g_free(jid->domainpart); + g_free(jid->resourcepart); + g_free(jid->barejid); + g_free(jid->fulljid); + free(jid); } } diff --git a/src/muc.c b/src/muc.c index 464d3e1b..1e706f6a 100644 --- a/src/muc.c +++ b/src/muc.c @@ -442,32 +442,20 @@ static void _free_room(ChatRoom *room) { if (room != NULL) { - if (room->room != NULL) { - g_free(room->room); - room->room = NULL; - } - if (room->nick != NULL) { - g_free(room->nick); - room->nick = NULL; - } - if (room->subject != NULL) { - g_free(room->subject); - room->subject = NULL; - } + free(room->room); + free(room->nick); + free(room->subject); if (room->roster != NULL) { g_hash_table_remove_all(room->roster); - room->roster = NULL; } if (room->nick_ac != NULL) { autocomplete_free(room->nick_ac); } if (room->nick_changes != NULL) { g_hash_table_remove_all(room->nick_changes); - room->nick_changes = NULL; } - g_free(room); + free(room); } - room = NULL; } static diff --git a/src/resource.c b/src/resource.c index 0a7838f3..86ba7e18 100644 --- a/src/resource.c +++ b/src/resource.c @@ -81,9 +81,10 @@ resource_compare_availability(Resource *first, Resource *second) void resource_destroy(Resource *resource) { - assert(resource != NULL); - FREE_SET_NULL(resource->name); - FREE_SET_NULL(resource->status); - FREE_SET_NULL(resource->caps_str); - FREE_SET_NULL(resource); + if (resource != NULL) { + free(resource->name); + free(resource->status); + free(resource->caps_str); + free(resource); + } } diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 8426de85..5c70f874 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -24,6 +24,7 @@ #include #include +#include "common.h" #include "tools/autocomplete.h" #include "tools/parser.h" @@ -59,10 +60,7 @@ void autocomplete_reset(Autocomplete ac) { ac->last_found = NULL; - if (ac->search_str != NULL) { - free(ac->search_str); - ac->search_str = NULL; - } + FREE_SET_NULL(ac->search_str); } void diff --git a/src/ui/console.c b/src/ui/console.c index 50d2b649..6efc1cf1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -784,7 +784,7 @@ cons_show_room_invite(const char * const invitor, const char * const room, notify_invite(display_from, room, reason); } - FREE_SET_NULL(display_from); + free(display_from); ui_console_dirty(); cons_alert(); diff --git a/src/ui/core.c b/src/ui/core.c index 126fe127..6b0b2d8d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -293,8 +293,9 @@ ui_incoming_msg(const char * const from, const char * const message, GTimeVal *tv_stamp, gboolean priv) { gboolean win_created = FALSE; - char *display_from; + char *display_from = NULL; win_type_t win_type; + if (priv) { win_type = WIN_PRIVATE; display_from = get_nick_from_full_jid(from); @@ -436,7 +437,7 @@ ui_incoming_msg(const char * const from, const char * const message, if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) notify_message(display_from, ui_index); - FREE_SET_NULL(display_from); + free(display_from); } void diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 10aa8a38..f9624f90 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -301,17 +301,16 @@ static void _caps_destroy(Capabilities *caps) { if (caps != NULL) { - FREE_SET_NULL(caps->category); - FREE_SET_NULL(caps->type); - FREE_SET_NULL(caps->name); - FREE_SET_NULL(caps->software); - FREE_SET_NULL(caps->software_version); - FREE_SET_NULL(caps->os); - FREE_SET_NULL(caps->os_version); + free(caps->category); + free(caps->type); + free(caps->name); + free(caps->software); + free(caps->software_version); + free(caps->os); + free(caps->os_version); if (caps->features != NULL) { g_slist_free_full(caps->features, free); - caps->features = NULL; } - FREE_SET_NULL(caps); + free(caps); } } diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index f072196d..6c87a8ac 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -385,7 +385,7 @@ _unavailable_handler(xmpp_conn_t * const conn, } } - FREE_SET_NULL(status_str); + free(status_str); jid_destroy(my_jid); jid_destroy(from_jid); @@ -471,8 +471,8 @@ _available_handler(xmpp_conn_t * const conn, last_activity); } - FREE_SET_NULL(status_str); - FREE_SET_NULL(show_str); + free(status_str); + free(show_str); jid_destroy(my_jid); jid_destroy(from_jid); @@ -556,10 +556,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, return 1; } - const char *jid = xmpp_conn_get_jid(conn); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - Jid *my_jid = jid_create(jid); Jid *from_jid = jid_create(from); + if (from_jid == NULL || from_jid->resourcepart == NULL) { + return 1; + } char *room = from_jid->barejid; char *nick = from_jid->resourcepart; @@ -592,7 +593,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle presence from room members } else { char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); - char *show_str, *status_str; + char *status_str; char *caps_key = NULL; if (stanza_contains_caps(stanza)) { @@ -608,12 +609,15 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, // handle nickname change if (stanza_is_room_nick_change(stanza)) { char *new_nick = stanza_get_new_nick(stanza); - muc_set_roster_pending_nick_change(room, new_nick, nick); + if (new_nick != NULL) { + muc_set_roster_pending_nick_change(room, new_nick, nick); + free(new_nick); + } } else { prof_handle_room_member_offline(room, nick, "offline", status_str); } } else { - show_str = stanza_get_show(stanza, "online"); + char *show_str = stanza_get_show(stanza, "online"); if (!muc_get_roster_received(room)) { muc_add_to_roster(room, nick, show_str, status_str, caps_key); } else { @@ -631,13 +635,13 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } } - FREE_SET_NULL(show_str); + free(show_str); } - FREE_SET_NULL(status_str); + free(status_str); + free(caps_key); } - jid_destroy(my_jid); jid_destroy(from_jid); return 1; diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 4d7d1f9d..61db0537 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -140,7 +140,7 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient, xmpp_stanza_set_name(chat_state, state); xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES); xmpp_stanza_add_child(msg, chat_state); - xmpp_stanza_release(chat_state); + xmpp_stanza_release(chat_state); } return msg; @@ -840,12 +840,11 @@ void stanza_destroy_form(DataForm *form) { if (form != NULL) { - FREE_SET_NULL(form->form_type); if (form->fields != NULL) { GSList *curr_field = form->fields; while (curr_field != NULL) { FormField *field = curr_field->data; - FREE_SET_NULL(field->var); + free(field->var); if ((field->values) != NULL) { g_slist_free_full(field->values, free); } @@ -854,6 +853,7 @@ stanza_destroy_form(DataForm *form) g_slist_free_full(form->fields, free); } + free(form->form_type); free(form); } } @@ -941,7 +941,7 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence) xmpp_stanza_add_child(presence, caps); xmpp_stanza_release(caps); xmpp_stanza_release(query); - FREE_SET_NULL(sha1); + g_free(sha1); } const char * -- cgit 1.4.1-2-gfad0 From a6e66cc57106402944445fc709625dcf88785a5b Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Sat, 3 Aug 2013 14:38:38 +0300 Subject: fixed memory leaks Also avoided several NULL pointer dereferences. --- src/ui/notifier.c | 6 ++--- src/xmpp/capabilities.c | 32 +++++++++++++------------- src/xmpp/iq.c | 20 +++++++++-------- src/xmpp/message.c | 6 +++++ src/xmpp/presence.c | 60 ++++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 85 insertions(+), 39 deletions(-) (limited to 'src/ui') diff --git a/src/ui/notifier.c b/src/ui/notifier.c index f43c8c25..403c215e 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -80,7 +80,7 @@ notify_invite(const char * const from, const char * const room, _notify(message->str, 10000, "Incoming message"); - g_string_free(message, FALSE); + g_string_free(message, TRUE); } void @@ -102,7 +102,7 @@ notify_room_message(const char * const handle, const char * const room, int win) _notify(text->str, 10000, "incoming message"); - g_string_free(text, FALSE); + g_string_free(text, TRUE); } void @@ -111,7 +111,7 @@ notify_subscription(const char * const from) GString *message = g_string_new("Subscription request: \n"); g_string_append(message, from); _notify(message->str, 10000, "Incomming message"); - g_string_free(message, FALSE); + g_string_free(message, TRUE); } void diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index f9624f90..ed3cf169 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -122,7 +122,7 @@ caps_create_sha1_str(xmpp_stanza_t * const query) GSList *form_names = NULL; DataForm *form = NULL; FormField *field = NULL; - GHashTable *forms = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)stanza_destroy_form); + GHashTable *forms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)stanza_destroy_form); GString *s = g_string_new(""); @@ -134,18 +134,18 @@ caps_create_sha1_str(xmpp_stanza_t * const query) lang = xmpp_stanza_get_attribute(child, "xml:lang"); name = xmpp_stanza_get_attribute(child, "name"); - GString *identity_str = g_string_new(g_strdup(category)); + GString *identity_str = g_string_new(category); g_string_append(identity_str, "/"); if (type != NULL) { - g_string_append(identity_str, g_strdup(type)); + g_string_append(identity_str, type); } g_string_append(identity_str, "/"); if (lang != NULL) { - g_string_append(identity_str, g_strdup(lang)); + g_string_append(identity_str, lang); } g_string_append(identity_str, "/"); if (name != NULL) { - g_string_append(identity_str, g_strdup(name)); + g_string_append(identity_str, name); } g_string_append(identity_str, "<"); identities = g_slist_insert_sorted(identities, g_strdup(identity_str->str), (GCompareFunc)octet_compare); @@ -156,8 +156,8 @@ caps_create_sha1_str(xmpp_stanza_t * const query) } else if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_X) == 0) { if (strcmp(xmpp_stanza_get_ns(child), STANZA_NS_DATA) == 0) { form = stanza_create_form(child); - form_names = g_slist_insert_sorted(form_names, strdup(form->form_type), (GCompareFunc)octet_compare); - g_hash_table_insert(forms, strdup(form->form_type), form); + form_names = g_slist_insert_sorted(form_names, g_strdup(form->form_type), (GCompareFunc)octet_compare); + g_hash_table_insert(forms, g_strdup(form->form_type), form); } } child = xmpp_stanza_get_next(child); @@ -165,13 +165,13 @@ caps_create_sha1_str(xmpp_stanza_t * const query) GSList *curr = identities; while (curr != NULL) { - g_string_append(s, strdup(curr->data)); + g_string_append(s, curr->data); curr = g_slist_next(curr); } curr = features; while (curr != NULL) { - g_string_append(s, strdup(curr->data)); + g_string_append(s, curr->data); g_string_append(s, "<"); curr = g_slist_next(curr); } @@ -179,17 +179,17 @@ caps_create_sha1_str(xmpp_stanza_t * const query) curr = form_names; while (curr != NULL) { form = g_hash_table_lookup(forms, curr->data); - g_string_append(s, strdup(form->form_type)); + g_string_append(s, form->form_type); g_string_append(s, "<"); GSList *curr_field = form->fields; while (curr_field != NULL) { field = curr_field->data; - g_string_append(s, strdup(field->var)); + g_string_append(s, field->var); g_string_append(s, "<"); GSList *curr_value = field->values; while (curr_value != NULL) { - g_string_append(s, strdup(curr_value->data)); + g_string_append(s, curr_value->data); g_string_append(s, "<"); curr_value = g_slist_next(curr_value); } @@ -215,10 +215,10 @@ caps_create_sha1_str(xmpp_stanza_t * const query) char *result = g_base64_encode(md_value, md_len); g_string_free(s, TRUE); - g_slist_free_full(identities, free); - g_slist_free_full(features, free); - g_slist_free_full(form_names, free); - //g_hash_table_destroy(forms); + g_slist_free_full(identities, g_free); + g_slist_free_full(features, g_free); + g_slist_free_full(form_names, g_free); + g_hash_table_destroy(forms); return result; } diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 48b561f0..742a2258 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -312,10 +312,10 @@ static void _identity_destroy(DiscoIdentity *identity) { if (identity != NULL) { - FREE_SET_NULL(identity->name); - FREE_SET_NULL(identity->type); - FREE_SET_NULL(identity->category); - FREE_SET_NULL(identity); + free(identity->name); + free(identity->type); + free(identity->category); + free(identity); } } @@ -323,9 +323,9 @@ static void _item_destroy(DiscoItem *item) { if (item != NULL) { - FREE_SET_NULL(item->jid); - FREE_SET_NULL(item->name); - FREE_SET_NULL(item); + free(item->jid); + free(item->name); + free(item); } } @@ -411,12 +411,13 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan log_info("Generated sha-1 does not match given:"); log_info("Generated : %s", generated_sha1); log_info("Given : %s", given_sha1); - FREE_SET_NULL(generated_sha1); + g_free(generated_sha1); g_strfreev(split); + free(caps_key); return 1; } - FREE_SET_NULL(generated_sha1); + g_free(generated_sha1); g_strfreev(split); // non supported hash, or legacy caps @@ -429,6 +430,7 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan // already cached if (caps_contains(caps_key)) { log_info("Client info already cached."); + free(caps_key); return 1; } diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 29d11958..95b3152a 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -212,6 +212,9 @@ _conference_message_handler(xmpp_conn_t * const conn, } Jid *jidp = jid_create(invitor_jid); + if (jidp == NULL) { + return 1; + } invitor = jidp->barejid; xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON); @@ -233,6 +236,9 @@ _conference_message_handler(xmpp_conn_t * const conn, } Jid *jidp = jid_create(from); + if (jidp == NULL) { + return 1; + } invitor = jidp->barejid; reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 6c87a8ac..93870088 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -156,14 +156,23 @@ presence_sub_request_find(char * search_str) gboolean presence_sub_request_exists(const char * const bare_jid) { - GSList *requests = autocomplete_get_list(sub_requests_ac); + gboolean result = FALSE; + GSList *requests_p = autocomplete_get_list(sub_requests_ac); + GSList *requests = requests_p; + while (requests != NULL) { if (strcmp(requests->data, bare_jid) == 0) { - return TRUE; + result = TRUE; + break; } requests = g_slist_next(requests); } - return FALSE; + + if (requests_p != NULL) { + g_slist_free_full(requests_p, free); + } + + return result; } void @@ -220,20 +229,28 @@ presence_update(const resource_presence_t presence_type, const char * const msg, static void _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence) { - GList *rooms = muc_get_active_room_list(); + GList *rooms_p = muc_get_active_room_list(); + GList *rooms = rooms_p; + while (rooms != NULL) { const char *room = rooms->data; const char *nick = muc_get_room_nick(room); - char *full_room_jid = create_fulljid(room, nick); - xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); - log_debug("Sending presence to room: %s", full_room_jid); - xmpp_send(conn, presence); - free(full_room_jid); + if (nick != NULL) { + char *full_room_jid = create_fulljid(room, nick); + + xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid); + log_debug("Sending presence to room: %s", full_room_jid); + xmpp_send(conn, presence); + free(full_room_jid); + } rooms = g_list_next(rooms); } - g_list_free(rooms); + + if (rooms_p != NULL) { + g_list_free(rooms_p); + } } void @@ -347,9 +364,13 @@ _subscribe_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - Jid *from_jid = jid_create(from); log_debug("Subscribe presence handler fired for %s", from); + Jid *from_jid = jid_create(from); + if (from_jid == NULL) { + return 1; + } + prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE); autocomplete_add(sub_requests_ac, strdup(from_jid->barejid)); @@ -368,6 +389,11 @@ _unavailable_handler(xmpp_conn_t * const conn, Jid *my_jid = jid_create(jid); Jid *from_jid = jid_create(from); + if (my_jid == NULL || from_jid == NULL) { + jid_destroy(my_jid); + jid_destroy(from_jid); + return 1; + } char *status_str = stanza_get_status(stanza, NULL); @@ -420,6 +446,11 @@ _available_handler(xmpp_conn_t * const conn, Jid *my_jid = jid_create(jid); Jid *from_jid = jid_create(from); + if (my_jid == NULL || from_jid == NULL) { + jid_destroy(my_jid); + jid_destroy(from_jid); + return 1; + } char *show_str = stanza_get_show(stanza, "online"); char *status_str = stanza_get_status(stanza, NULL); @@ -515,6 +546,10 @@ _get_caps_key(xmpp_stanza_t * const stanza) log_debug("Presence contains capabilities."); + if (node == NULL) { + return NULL; + } + // xep-0115 if ((hash_type != NULL) && (strcmp(hash_type, "sha-1") == 0)) { log_debug("Hash type %s supported.", hash_type); @@ -544,6 +579,8 @@ _get_caps_key(xmpp_stanza_t * const stanza) g_string_free(id_str, TRUE); } + g_free(node); + return caps_key; } @@ -626,6 +663,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, if (old_nick != NULL) { muc_add_to_roster(room, nick, show_str, status_str, caps_key); prof_handle_room_member_nick_change(room, old_nick, nick); + free(old_nick); } else { if (!muc_nick_in_roster(room, nick)) { prof_handle_room_member_online(room, nick, show_str, status_str, caps_key); -- cgit 1.4.1-2-gfad0 From 021d0955368272456434db4061e6c6b15bbd77db Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Sat, 24 Aug 2013 00:39:03 +0300 Subject: small refactoring in statusbar.c --- src/ui/statusbar.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/ui') 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 #include #include @@ -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; } -- cgit 1.4.1-2-gfad0 From c7ec06ff65f6b49f264d3a3a21c64615c9c1f090 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Sun, 25 Aug 2013 14:52:25 +0300 Subject: removed strdup from g_string_append --- src/ui/console.c | 10 +++++----- src/ui/core.c | 12 ++++++------ src/xmpp/roster.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/ui') 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/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); -- cgit 1.4.1-2-gfad0