mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Merge remote-tracking branch 'dmitry/memleaks' into nextdev
This commit is contained in:
commit
51b2137705
@ -1142,7 +1142,6 @@ cmd_execute_default(const char * const inp)
|
|||||||
ui_current_print_line("You are not currently connected.");
|
ui_current_print_line("You are not currently connected.");
|
||||||
} else {
|
} else {
|
||||||
message_send_groupchat(inp, recipient);
|
message_send_groupchat(inp, recipient);
|
||||||
free(recipient);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1160,7 +1159,6 @@ cmd_execute_default(const char * const inp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui_outgoing_msg("me", recipient, inp);
|
ui_outgoing_msg("me", recipient, inp);
|
||||||
free(recipient);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1170,7 +1168,6 @@ cmd_execute_default(const char * const inp)
|
|||||||
} else {
|
} else {
|
||||||
message_send(inp, recipient);
|
message_send(inp, recipient);
|
||||||
ui_outgoing_msg("me", recipient, inp);
|
ui_outgoing_msg("me", recipient, inp);
|
||||||
free(recipient);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1184,7 +1181,6 @@ cmd_execute_default(const char * const inp)
|
|||||||
} else {
|
} else {
|
||||||
message_send_duck(inp);
|
message_send_duck(inp);
|
||||||
ui_duck(inp);
|
ui_duck(inp);
|
||||||
free(recipient);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1192,6 +1188,8 @@ cmd_execute_default(const char * const inp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(recipient);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1218,7 +1216,9 @@ _cmd_complete_parameters(char *input, int *size)
|
|||||||
|
|
||||||
// autocomplete nickname in chat rooms
|
// autocomplete nickname in chat rooms
|
||||||
if (ui_current_win_type() == WIN_MUC) {
|
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) {
|
if (nick_ac != NULL) {
|
||||||
gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ;
|
gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ;
|
||||||
|
|
||||||
@ -2008,6 +2008,8 @@ _cmd_who(gchar **args, struct cmd_help_t help)
|
|||||||
ui_room_roster(room, filtered, presence);
|
ui_room_roster(room, filtered, presence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(room);
|
||||||
|
|
||||||
// not in groupchat window
|
// not in groupchat window
|
||||||
} else {
|
} else {
|
||||||
cons_show("");
|
cons_show("");
|
||||||
@ -2172,6 +2174,8 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
ui_current_print_line("No such participant \"%s\" in room.", usr);
|
ui_current_print_line("No such participant \"%s\" in room.", usr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(room_name);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -2493,17 +2497,20 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
|||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
win_type_t win_type = ui_current_win_type();
|
win_type_t win_type = ui_current_win_type();
|
||||||
PContact pcontact = NULL;
|
PContact pcontact = NULL;
|
||||||
|
char *recipient;
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recipient = ui_current_recipient();
|
||||||
|
|
||||||
switch (win_type)
|
switch (win_type)
|
||||||
{
|
{
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
if (usr != NULL) {
|
if (usr != NULL) {
|
||||||
pcontact = muc_get_participant(ui_current_recipient(), usr);
|
pcontact = muc_get_participant(recipient, usr);
|
||||||
if (pcontact != NULL) {
|
if (pcontact != NULL) {
|
||||||
cons_show_info(pcontact);
|
cons_show_info(pcontact);
|
||||||
} else {
|
} else {
|
||||||
@ -2517,11 +2524,11 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
|||||||
if (usr != NULL) {
|
if (usr != NULL) {
|
||||||
cons_show("No parameter required for /info in chat.");
|
cons_show("No parameter required for /info in chat.");
|
||||||
} else {
|
} else {
|
||||||
pcontact = roster_get_contact(ui_current_recipient());
|
pcontact = roster_get_contact(recipient);
|
||||||
if (pcontact != NULL) {
|
if (pcontact != NULL) {
|
||||||
cons_show_info(pcontact);
|
cons_show_info(pcontact);
|
||||||
} else {
|
} else {
|
||||||
cons_show("No such contact \"%s\" in roster.", ui_current_recipient());
|
cons_show("No such contact \"%s\" in roster.", recipient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -2529,7 +2536,7 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
|||||||
if (usr != NULL) {
|
if (usr != NULL) {
|
||||||
ui_current_print_line("No parameter required when in chat.");
|
ui_current_print_line("No parameter required when in chat.");
|
||||||
} else {
|
} else {
|
||||||
Jid *jid = jid_create(ui_current_recipient());
|
Jid *jid = jid_create(recipient);
|
||||||
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
|
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
|
||||||
if (pcontact != NULL) {
|
if (pcontact != NULL) {
|
||||||
cons_show_info(pcontact);
|
cons_show_info(pcontact);
|
||||||
@ -2559,6 +2566,8 @@ _cmd_info(gchar **args, struct cmd_help_t help)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(recipient);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2568,6 +2577,7 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
|
|||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
win_type_t win_type = ui_current_win_type();
|
win_type_t win_type = ui_current_win_type();
|
||||||
PContact pcontact = NULL;
|
PContact pcontact = NULL;
|
||||||
|
char *recipient;
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
@ -2578,13 +2588,15 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
|
|||||||
{
|
{
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
if (args[0] != NULL) {
|
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) {
|
if (pcontact != NULL) {
|
||||||
Resource *resource = p_contact_get_resource(pcontact, args[0]);
|
Resource *resource = p_contact_get_resource(pcontact, args[0]);
|
||||||
cons_show_caps(args[0], resource);
|
cons_show_caps(args[0], resource);
|
||||||
} else {
|
} else {
|
||||||
cons_show("No such participant \"%s\" in room.", args[0]);
|
cons_show("No such participant \"%s\" in room.", args[0]);
|
||||||
}
|
}
|
||||||
|
free(recipient);
|
||||||
} else {
|
} else {
|
||||||
cons_show("No nickname supplied to /caps in chat room.");
|
cons_show("No nickname supplied to /caps in chat room.");
|
||||||
}
|
}
|
||||||
@ -2617,10 +2629,15 @@ _cmd_caps(gchar **args, struct cmd_help_t help)
|
|||||||
if (args[0] != NULL) {
|
if (args[0] != NULL) {
|
||||||
cons_show("No parameter needed to /caps when in private chat.");
|
cons_show("No parameter needed to /caps when in private chat.");
|
||||||
} else {
|
} else {
|
||||||
Jid *jid = jid_create(ui_current_recipient());
|
recipient = ui_current_recipient();
|
||||||
pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
|
Jid *jid = jid_create(recipient);
|
||||||
Resource *resource = p_contact_get_resource(pcontact, jid->resourcepart);
|
if (jid) {
|
||||||
cons_show_caps(jid->resourcepart, resource);
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -2637,6 +2654,7 @@ _cmd_software(gchar **args, struct cmd_help_t help)
|
|||||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||||
win_type_t win_type = ui_current_win_type();
|
win_type_t win_type = ui_current_win_type();
|
||||||
PContact pcontact = NULL;
|
PContact pcontact = NULL;
|
||||||
|
char *recipient;
|
||||||
|
|
||||||
if (conn_status != JABBER_CONNECTED) {
|
if (conn_status != JABBER_CONNECTED) {
|
||||||
cons_show("You are not currently connected.");
|
cons_show("You are not currently connected.");
|
||||||
@ -2647,14 +2665,16 @@ _cmd_software(gchar **args, struct cmd_help_t help)
|
|||||||
{
|
{
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
if (args[0] != NULL) {
|
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) {
|
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);
|
iq_send_software_version(jid->fulljid);
|
||||||
jid_destroy(jid);
|
jid_destroy(jid);
|
||||||
} else {
|
} else {
|
||||||
cons_show("No such participant \"%s\" in room.", args[0]);
|
cons_show("No such participant \"%s\" in room.", args[0]);
|
||||||
}
|
}
|
||||||
|
free(recipient);
|
||||||
} else {
|
} else {
|
||||||
cons_show("No nickname supplied to /software in chat room.");
|
cons_show("No nickname supplied to /software in chat room.");
|
||||||
}
|
}
|
||||||
@ -2664,11 +2684,12 @@ _cmd_software(gchar **args, struct cmd_help_t help)
|
|||||||
if (args[0] != NULL) {
|
if (args[0] != NULL) {
|
||||||
Jid *jid = jid_create(args[0]);
|
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.");
|
cons_show("You must provide a full jid to the /software command.");
|
||||||
} else {
|
} else {
|
||||||
iq_send_software_version(jid->fulljid);
|
iq_send_software_version(jid->fulljid);
|
||||||
}
|
}
|
||||||
|
jid_destroy(jid);
|
||||||
} else {
|
} else {
|
||||||
cons_show("You must provide a jid to the /software command.");
|
cons_show("You must provide a jid to the /software command.");
|
||||||
}
|
}
|
||||||
@ -2677,7 +2698,9 @@ _cmd_software(gchar **args, struct cmd_help_t help)
|
|||||||
if (args[0] != NULL) {
|
if (args[0] != NULL) {
|
||||||
cons_show("No parameter needed to /software when in private chat.");
|
cons_show("No parameter needed to /software when in private chat.");
|
||||||
} else {
|
} else {
|
||||||
iq_send_software_version(ui_current_recipient());
|
recipient = ui_current_recipient();
|
||||||
|
iq_send_software_version(recipient);
|
||||||
|
free(recipient);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
14
src/common.h
14
src/common.h
@ -42,18 +42,16 @@
|
|||||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||||
|
|
||||||
#define FREE_SET_NULL(resource) \
|
#define FREE_SET_NULL(resource) \
|
||||||
{ \
|
do { \
|
||||||
if (resource != NULL) { \
|
free(resource); \
|
||||||
free(resource); \
|
resource = NULL; \
|
||||||
resource = NULL; \
|
} while (0)
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define GFREE_SET_NULL(resource) \
|
#define GFREE_SET_NULL(resource) \
|
||||||
{ \
|
do { \
|
||||||
g_free(resource); \
|
g_free(resource); \
|
||||||
resource = NULL; \
|
resource = NULL; \
|
||||||
}
|
} while (0)
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CONTACT_OFFLINE,
|
CONTACT_OFFLINE,
|
||||||
|
56
src/jid.c
56
src/jid.c
@ -34,13 +34,14 @@ jid_create(const gchar * const str)
|
|||||||
{
|
{
|
||||||
Jid *result = NULL;
|
Jid *result = NULL;
|
||||||
|
|
||||||
if (str == NULL) {
|
/* if str is NULL g_strdup returns NULL */
|
||||||
|
gchar *trimmed = g_strdup(str);
|
||||||
|
if (trimmed == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *trimmed = g_strdup(str);
|
|
||||||
|
|
||||||
if (strlen(trimmed) == 0) {
|
if (strlen(trimmed) == 0) {
|
||||||
|
g_free(trimmed);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,10 +51,12 @@ jid_create(const gchar * const str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!g_utf8_validate(trimmed, -1, NULL)) {
|
if (!g_utf8_validate(trimmed, -1, NULL)) {
|
||||||
|
g_free(trimmed);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = malloc(sizeof(struct jid_t));
|
result = malloc(sizeof(struct jid_t));
|
||||||
|
result->str = NULL;
|
||||||
result->localpart = NULL;
|
result->localpart = NULL;
|
||||||
result->domainpart = NULL;
|
result->domainpart = NULL;
|
||||||
result->resourcepart = NULL;
|
result->resourcepart = NULL;
|
||||||
@ -81,13 +84,11 @@ jid_create(const gchar * const str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result->domainpart == NULL) {
|
if (result->domainpart == NULL) {
|
||||||
free(trimmed);
|
jid_destroy(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result->str = g_strdup(trimmed);
|
result->str = trimmed;
|
||||||
|
|
||||||
free(trimmed);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -107,12 +108,12 @@ void
|
|||||||
jid_destroy(Jid *jid)
|
jid_destroy(Jid *jid)
|
||||||
{
|
{
|
||||||
if (jid != NULL) {
|
if (jid != NULL) {
|
||||||
FREE_SET_NULL(jid->str);
|
GFREE_SET_NULL(jid->str);
|
||||||
FREE_SET_NULL(jid->localpart);
|
GFREE_SET_NULL(jid->localpart);
|
||||||
FREE_SET_NULL(jid->domainpart);
|
GFREE_SET_NULL(jid->domainpart);
|
||||||
FREE_SET_NULL(jid->resourcepart);
|
GFREE_SET_NULL(jid->resourcepart);
|
||||||
FREE_SET_NULL(jid->barejid);
|
GFREE_SET_NULL(jid->barejid);
|
||||||
FREE_SET_NULL(jid->fulljid);
|
GFREE_SET_NULL(jid->fulljid);
|
||||||
FREE_SET_NULL(jid);
|
FREE_SET_NULL(jid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,17 +182,17 @@ char *
|
|||||||
get_room_from_full_jid(const char * const full_room_jid)
|
get_room_from_full_jid(const char * const full_room_jid)
|
||||||
{
|
{
|
||||||
char **tokens = g_strsplit(full_room_jid, "/", 0);
|
char **tokens = g_strsplit(full_room_jid, "/", 0);
|
||||||
char *room_part;
|
char *room_part = NULL;
|
||||||
|
|
||||||
if (tokens == NULL || tokens[0] == NULL) {
|
if (tokens != NULL) {
|
||||||
return NULL;
|
if (tokens[0] != NULL) {
|
||||||
} else {
|
room_part = strdup(tokens[0]);
|
||||||
room_part = strdup(tokens[0]);
|
}
|
||||||
|
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
|
|
||||||
return room_part;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return room_part;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -203,16 +204,15 @@ char *
|
|||||||
get_nick_from_full_jid(const char * const full_room_jid)
|
get_nick_from_full_jid(const char * const full_room_jid)
|
||||||
{
|
{
|
||||||
char **tokens = g_strsplit(full_room_jid, "/", 0);
|
char **tokens = g_strsplit(full_room_jid, "/", 0);
|
||||||
char *nick_part;
|
char *nick_part = NULL;
|
||||||
|
|
||||||
if (tokens == NULL || tokens[1] == NULL) {
|
if (tokens != NULL) {
|
||||||
return NULL;
|
if (tokens[0] != NULL && tokens[1] != NULL) {
|
||||||
} else {
|
nick_part = strdup(tokens[1]);
|
||||||
nick_part = strdup(tokens[1]);
|
}
|
||||||
|
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
|
|
||||||
return nick_part;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
return nick_part;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user