fixed several memory leaks in command.c and jid.c

This commit is contained in:
Dmitry Podgorny
2013-07-31 01:51:07 +03:00
parent c73d181690
commit 5505387c37
2 changed files with 63 additions and 40 deletions

View File

@@ -1121,7 +1121,6 @@ cmd_execute_default(const char * const inp)
ui_current_print_line("You are not currently connected.");
} else {
message_send_groupchat(inp, recipient);
free(recipient);
}
break;
@@ -1139,7 +1138,6 @@ cmd_execute_default(const char * const inp)
}
ui_outgoing_msg("me", recipient, inp);
free(recipient);
}
break;
@@ -1149,7 +1147,6 @@ cmd_execute_default(const char * const inp)
} else {
message_send(inp, recipient);
ui_outgoing_msg("me", recipient, inp);
free(recipient);
}
break;
@@ -1163,7 +1160,6 @@ cmd_execute_default(const char * const inp)
} else {
message_send_duck(inp);
ui_duck(inp);
free(recipient);
}
break;
@@ -1171,6 +1167,8 @@ cmd_execute_default(const char * const inp)
break;
}
free(recipient);
return TRUE;
}
@@ -1197,7 +1195,9 @@ _cmd_complete_parameters(char *input, int *size)
// autocomplete nickname in chat rooms
if (ui_current_win_type() == WIN_MUC) {
Autocomplete nick_ac = muc_get_roster_ac(ui_current_recipient());
char *recipient = ui_current_recipient();
Autocomplete nick_ac = muc_get_roster_ac(recipient);
free(recipient);
if (nick_ac != NULL) {
gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ;
@@ -1979,6 +1979,8 @@ _cmd_who(gchar **args, struct cmd_help_t help)
ui_room_roster(room, filtered, presence);
}
free(room);
// not in groupchat window
} else {
cons_show("");
@@ -2143,6 +2145,8 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
ui_current_print_line("No such participant \"%s\" in room.", usr);
}
free(room_name);
return TRUE;
} else {
@@ -2464,17 +2468,20 @@ _cmd_info(gchar **args, struct cmd_help_t help)
jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type();
PContact pcontact = NULL;
char *recipient;
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
return TRUE;
}
recipient = ui_current_recipient();
switch (win_type)
{
case WIN_MUC:
if (usr != NULL) {
pcontact = muc_get_participant(ui_current_recipient(), usr);
pcontact = muc_get_participant(recipient, usr);
if (pcontact != NULL) {
cons_show_info(pcontact);
} else {
@@ -2488,11 +2495,11 @@ _cmd_info(gchar **args, struct cmd_help_t help)
if (usr != NULL) {
cons_show("No parameter required for /info in chat.");
} else {
pcontact = roster_get_contact(ui_current_recipient());
pcontact = roster_get_contact(recipient);
if (pcontact != NULL) {
cons_show_info(pcontact);
} else {
cons_show("No such contact \"%s\" in roster.", ui_current_recipient());
cons_show("No such contact \"%s\" in roster.", recipient);
}
}
break;
@@ -2500,7 +2507,7 @@ _cmd_info(gchar **args, struct cmd_help_t help)
if (usr != NULL) {
ui_current_print_line("No parameter required when in chat.");
} else {
Jid *jid = jid_create(ui_current_recipient());
Jid *jid = jid_create(recipient);
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
if (pcontact != NULL) {
cons_show_info(pcontact);
@@ -2530,6 +2537,8 @@ _cmd_info(gchar **args, struct cmd_help_t help)
break;
}
free(recipient);
return TRUE;
}
@@ -2539,6 +2548,7 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type();
PContact pcontact = NULL;
char *recipient;
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
@@ -2549,13 +2559,15 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
{
case WIN_MUC:
if (args[0] != NULL) {
pcontact = muc_get_participant(ui_current_recipient(), args[0]);
recipient = ui_current_recipient();
pcontact = muc_get_participant(recipient, args[0]);
if (pcontact != NULL) {
Resource *resource = p_contact_get_resource(pcontact, args[0]);
cons_show_caps(args[0], resource);
} else {
cons_show("No such participant \"%s\" in room.", args[0]);
}
free(recipient);
} else {
cons_show("No nickname supplied to /caps in chat room.");
}
@@ -2588,10 +2600,15 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
if (args[0] != NULL) {
cons_show("No parameter needed to /caps when in private chat.");
} else {
Jid *jid = jid_create(ui_current_recipient());
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart);
cons_show_caps(jid->resourcepart, resource);
recipient = ui_current_recipient();
Jid *jid = jid_create(recipient);
if (jid) {
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart);
cons_show_caps(jid->resourcepart, resource);
jid_destroy(jid);
}
free(recipient);
}
break;
default:
@@ -2608,6 +2625,7 @@ _cmd_software(gchar **args, struct cmd_help_t help)
jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type();
PContact pcontact = NULL;
char *recipient;
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
@@ -2618,14 +2636,16 @@ _cmd_software(gchar **args, struct cmd_help_t help)
{
case WIN_MUC:
if (args[0] != NULL) {
pcontact = muc_get_participant(ui_current_recipient(), args[0]);
recipient = ui_current_recipient();
pcontact = muc_get_participant(recipient, args[0]);
if (pcontact != NULL) {
Jid *jid = jid_create_from_bare_and_resource(ui_current_recipient(), args[0]);
Jid *jid = jid_create_from_bare_and_resource(recipient, args[0]);
iq_send_software_version(jid->fulljid);
jid_destroy(jid);
} else {
cons_show("No such participant \"%s\" in room.", args[0]);
}
free(recipient);
} else {
cons_show("No nickname supplied to /software in chat room.");
}
@@ -2635,11 +2655,12 @@ _cmd_software(gchar **args, struct cmd_help_t help)
if (args[0] != NULL) {
Jid *jid = jid_create(args[0]);
if (jid->fulljid == NULL) {
if (jid == NULL || jid->fulljid == NULL) {
cons_show("You must provide a full jid to the /software command.");
} else {
iq_send_software_version(jid->fulljid);
}
jid_destroy(jid);
} else {
cons_show("You must provide a jid to the /software command.");
}
@@ -2648,7 +2669,9 @@ _cmd_software(gchar **args, struct cmd_help_t help)
if (args[0] != NULL) {
cons_show("No parameter needed to /software when in private chat.");
} else {
iq_send_software_version(ui_current_recipient());
recipient = ui_current_recipient();
iq_send_software_version(recipient);
free(recipient);
}
break;
default: