1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

fixed memory leaks in various files

This commit is contained in:
Dmitry Podgorny 2013-08-25 14:54:34 +03:00
parent c7ec06ff65
commit b1bfdf650a
5 changed files with 60 additions and 29 deletions

View File

@ -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 *

View File

@ -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_muc);
xmpp_stanza_release(feature_discoinfo);
xmpp_stanza_release(feature_discoitems);
xmpp_stanza_release(feature_caps);
xmpp_stanza_release(feature_ping);
xmpp_stanza_release(feature_version);
xmpp_stanza_release(feature_muc);
xmpp_stanza_release(feature_discoitems);
xmpp_stanza_release(feature_discoinfo);
xmpp_stanza_release(feature_chatstates);
xmpp_stanza_release(feature_caps);
xmpp_stanza_release(identity);
return query;
}

View File

@ -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);
}
@ -437,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;
@ -458,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;
@ -478,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);
@ -492,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);
}

View File

@ -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);

View File

@ -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);