1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-21 18:24:14 -04:00

Fixed various memory leaks

This commit is contained in:
James Booth 2014-11-01 01:48:36 +00:00
parent 51164398e3
commit c4412fe823
13 changed files with 47 additions and 16 deletions

View File

@ -1,4 +1,9 @@
Test with valgrind using new commands
/affiliation
/role
/occupants
/privileges
/ping
Update website help

View File

@ -3,7 +3,6 @@
Memcheck:Leak
...
fun:_dl_init
obj:/lib/x86_64-linux-gnu/ld-2.17.so
...
}

View File

@ -2348,16 +2348,15 @@ _form_field_autocomplete(char *input, int *size)
if (((g_strcmp0(split[1], "add") == 0) || (g_strcmp0(split[1], "remove") == 0))
&& field_type == FIELD_LIST_MULTI) {
found = autocomplete_param_with_ac(input, size, beginning->str, value_ac, TRUE);
g_string_free(beginning, TRUE);
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_TEXT_MULTI) {
found = autocomplete_param_with_ac(input, size, beginning->str, value_ac, TRUE);
g_string_free(beginning, TRUE);
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_JID_MULTI) {
found = autocomplete_param_with_ac(input, size, beginning->str, value_ac, TRUE);
g_string_free(beginning, TRUE);
}
g_string_free(beginning, TRUE);
}
} else if (g_strv_length(split) == 2) {

View File

@ -2077,15 +2077,15 @@ cmd_form(gchar **args, struct cmd_help_t help)
iq_submit_room_config(room, current->form);
}
if (g_strcmp0(args[0], "cancel") == 0) {
iq_room_config_cancel(room);
}
if ((g_strcmp0(args[0], "submit") == 0) ||
(g_strcmp0(args[0], "cancel") == 0)) {
if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
if (current->form) {
cmd_autocomplete_remove_form_fields(current->form);
}
wins_close_current();
current = wins_get_by_recipient(room);
if (current == NULL) {
@ -2474,6 +2474,7 @@ cmd_rooms(gchar **args, struct cmd_help_t help)
if (args[0] == NULL) {
ProfAccount *account = accounts_get_account(jabber_get_account_name());
iq_room_list_request(account->muc_service);
account_free(account);
} else {
iq_room_list_request(args[0]);
}

View File

@ -739,6 +739,7 @@ _cons_show_account(ProfAccount *account)
win_save_vprint(console, '-', NULL, NO_DATE, 0, "", "");
Jid *jidp = jid_create_from_bare_and_resource(account->jid, resource->name);
Capabilities *caps = caps_lookup(jidp->fulljid);
jid_destroy(jidp);
if (caps != NULL) {
// show identity

View File

@ -1519,7 +1519,7 @@ _ui_show_room_disco_info(const char * const room, GSList *identities, GSList *fe
identity_str = g_string_append(identity_str, identity->category);
}
win_save_print(window, '!', NULL, 0, 0, "", identity_str->str);
g_string_free(identity_str, FALSE);
g_string_free(identity_str, TRUE);
identities = g_slist_next(identities);
}

View File

@ -264,6 +264,7 @@ win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occup
Jid *jidp = jid_create_from_bare_and_resource(room, occupant->nick);
Capabilities *caps = caps_lookup(jidp->fulljid);
jid_destroy(jidp);
if (caps) {
// show identity
@ -378,6 +379,7 @@ win_show_info(ProfWin *window, PContact contact)
Jid *jidp = jid_create_from_bare_and_resource(barejid, resource->name);
Capabilities *caps = caps_lookup(jidp->fulljid);
jid_destroy(jidp);
if (caps) {
// show identity

View File

@ -453,9 +453,9 @@ _connection_handler(xmpp_conn_t * const conn,
_connection_free_saved_details();
}
Jid *myJid = jid_create(jabber_get_fulljid());
jabber_conn.domain = strdup(myJid->domainpart);
jid_destroy(myJid);
Jid *my_jid = jid_create(jabber_get_fulljid());
jabber_conn.domain = strdup(my_jid->domainpart);
jid_destroy(my_jid);
chat_sessions_init();

View File

@ -458,6 +458,8 @@ _form_tag_exists(DataForm *form, const char * const tag)
}
curr = g_list_next(curr);
}
g_list_free(tags);
return FALSE;
}

View File

@ -158,6 +158,8 @@ _iq_disco_info_request(gchar *jid)
xmpp_id_handler_add(conn, _disco_info_response_handler, id, NULL);
free(id);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
@ -172,6 +174,8 @@ _iq_room_info_request(gchar *room)
xmpp_id_handler_add(conn, _disco_info_response_handler, id, room);
free(id);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}

View File

@ -373,6 +373,7 @@ _presence_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
log_info("Error joining room: %s, reason: %s", fulljid->barejid, error_cond);
handle_room_join_error(fulljid->barejid, error_cond);
jid_destroy(fulljid);
return 1;
}
@ -753,7 +754,7 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void *
handle_leave_room(room);
}
g_slist_free(status_codes);
g_slist_free_full(status_codes, free);
}
// self online
@ -797,6 +798,8 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void *
} else {
handle_room_occupant_offline(room, nick, "offline", status_str);
}
g_slist_free_full(status_codes, free);
}
// room occupant online

View File

@ -113,6 +113,7 @@ stanza_create_bookmarks_pubsub_add(xmpp_ctx_t *ctx, const char * const jid,
xmpp_stanza_set_name(stanza, STANZA_NAME_IQ);
char *id = create_unique_id("bookmark_add");
xmpp_stanza_set_id(stanza, id);
free(id);
xmpp_stanza_set_type(stanza, STANZA_TYPE_SET);
xmpp_stanza_t *pubsub = xmpp_stanza_new(ctx);
@ -1054,6 +1055,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
if (muc_active(from_jid->barejid)) {
char *nick = muc_nick(from_jid->barejid);
if (g_strcmp0(from_jid->resourcepart, nick) == 0) {
jid_destroy(from_jid);
return TRUE;
}
}
@ -1065,6 +1067,7 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
char *nick = muc_nick(from_jid->barejid);
char *old_nick = muc_old_nick(from_jid->barejid, new_nick);
if (g_strcmp0(old_nick, nick) == 0) {
jid_destroy(from_jid);
return TRUE;
}
}
@ -1090,7 +1093,7 @@ stanza_get_status_codes_by_ns(xmpp_stanza_t * const stanza, char *ns)
if (g_strcmp0(name, STANZA_NAME_STATUS) == 0) {
char *code = xmpp_stanza_get_attribute(child, STANZA_ATTR_CODE);
if (code) {
codes = g_slist_append(codes, code);
codes = g_slist_append(codes, strdup(code));
}
}
child = xmpp_stanza_get_next(child);

View File

@ -3,6 +3,7 @@
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "xmpp/xmpp.h"
@ -59,9 +60,21 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
{
mock_accounts_get_account();
CommandHelp *help = malloc(sizeof(CommandHelp));
ProfAccount *account = malloc(sizeof(ProfAccount));
account->muc_service = "default_conf_server";
gchar *args[] = { NULL };
ProfAccount *account = malloc(sizeof(ProfAccount));
account->name = NULL;
account->jid = NULL;
account->password = NULL;
account->resource = NULL;
account->server = NULL;
account->last_presence = NULL;
account->login_presence = NULL;
account->muc_nick = NULL;
account->otr_policy = NULL;
account->otr_manual = NULL;
account->otr_opportunistic = NULL;
account->otr_always = NULL;
account->muc_service = strdup("default_conf_server");
mock_connection_status(JABBER_CONNECTED);
mock_connection_account_name("account_name");
@ -75,7 +88,6 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
assert_true(result);
free(help);
free(account);
}
void cmd_rooms_arg_used_when_passed(void **state)