fixed several memory leaks
And infinity loop in stanza_destroy_form().
This commit is contained in:
@@ -123,7 +123,7 @@ jabber_connect_with_account(const ProfAccount * const account,
|
|||||||
// connect with fulljid
|
// connect with fulljid
|
||||||
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource);
|
||||||
jabber_conn_status_t result = _jabber_connect(jidp->fulljid, passwd, account->server);
|
jabber_conn_status_t result = _jabber_connect(jidp->fulljid, passwd, account->server);
|
||||||
free(jidp);
|
jid_destroy(jidp);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -334,6 +334,7 @@ int
|
|||||||
connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata)
|
void * const userdata)
|
||||||
{
|
{
|
||||||
|
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||||
gchar *err_msg = NULL;
|
gchar *err_msg = NULL;
|
||||||
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
|
xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
|
||||||
@@ -347,7 +348,10 @@ connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
// check for text
|
// check for text
|
||||||
if (text_stanza != NULL) {
|
if (text_stanza != NULL) {
|
||||||
err_msg = xmpp_stanza_get_text(text_stanza);
|
err_msg = xmpp_stanza_get_text(text_stanza);
|
||||||
prof_handle_error_message(from, err_msg);
|
if (err_msg != NULL) {
|
||||||
|
prof_handle_error_message(from, err_msg);
|
||||||
|
xmpp_free(ctx, err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2]
|
// TODO : process 'type' attribute from <error/> [RFC6120, 8.3.2]
|
||||||
|
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ static int
|
|||||||
_conference_message_handler(xmpp_conn_t * const conn,
|
_conference_message_handler(xmpp_conn_t * const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata)
|
xmpp_stanza_t * const stanza, void * const userdata)
|
||||||
{
|
{
|
||||||
|
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *x_muc = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
xmpp_stanza_t *x_muc = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
|
||||||
xmpp_stanza_t *x_groupchat = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
|
xmpp_stanza_t *x_groupchat = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
@@ -219,6 +220,9 @@ _conference_message_handler(xmpp_conn_t * const conn,
|
|||||||
|
|
||||||
prof_handle_room_invite(INVITE_MEDIATED, invitor, room, reason);
|
prof_handle_room_invite(INVITE_MEDIATED, invitor, room, reason);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
|
if (reason != NULL) {
|
||||||
|
xmpp_free(ctx, reason);
|
||||||
|
}
|
||||||
|
|
||||||
// XEP-0429
|
// XEP-0429
|
||||||
} else if (x_groupchat != NULL) {
|
} else if (x_groupchat != NULL) {
|
||||||
@@ -244,6 +248,7 @@ static int
|
|||||||
_groupchat_message_handler(xmpp_conn_t * const conn,
|
_groupchat_message_handler(xmpp_conn_t * const conn,
|
||||||
xmpp_stanza_t * const stanza, void * const userdata)
|
xmpp_stanza_t * const stanza, void * const userdata)
|
||||||
{
|
{
|
||||||
|
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||||
char *message = NULL;
|
char *message = NULL;
|
||||||
char *room_jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
char *room_jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
Jid *jid = jid_create(room_jid);
|
Jid *jid = jid_create(room_jid);
|
||||||
@@ -259,6 +264,7 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
|
|||||||
prof_handle_room_subject(jid->barejid, message);
|
prof_handle_room_subject(jid->barejid, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jid_destroy(jid);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// handle other room broadcasts
|
// handle other room broadcasts
|
||||||
@@ -268,9 +274,11 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
|
|||||||
message = xmpp_stanza_get_text(body);
|
message = xmpp_stanza_get_text(body);
|
||||||
if (message != NULL) {
|
if (message != NULL) {
|
||||||
prof_handle_room_broadcast(room_jid, message);
|
prof_handle_room_broadcast(room_jid, message);
|
||||||
|
xmpp_free(ctx, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jid_destroy(jid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,12 +286,14 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
|
|||||||
|
|
||||||
if (!jid_is_valid_room_form(jid)) {
|
if (!jid_is_valid_room_form(jid)) {
|
||||||
log_error("Invalid room JID: %s", jid->str);
|
log_error("Invalid room JID: %s", jid->str);
|
||||||
|
jid_destroy(jid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// room not active in profanity
|
// room not active in profanity
|
||||||
if (!muc_room_is_active(jid)) {
|
if (!muc_room_is_active(jid)) {
|
||||||
log_error("Message recieved for inactive chat room: %s", jid->str);
|
log_error("Message recieved for inactive chat room: %s", jid->str);
|
||||||
|
jid_destroy(jid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,11 +304,14 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
|
|||||||
|
|
||||||
// check for and deal with message
|
// check for and deal with message
|
||||||
if (body != NULL) {
|
if (body != NULL) {
|
||||||
char *message = xmpp_stanza_get_text(body);
|
message = xmpp_stanza_get_text(body);
|
||||||
if (delayed) {
|
if (message != NULL) {
|
||||||
prof_handle_room_history(jid->barejid, jid->resourcepart, tv_stamp, message);
|
if (delayed) {
|
||||||
} else {
|
prof_handle_room_history(jid->barejid, jid->resourcepart, tv_stamp, message);
|
||||||
prof_handle_room_message(jid->barejid, jid->resourcepart, message);
|
} else {
|
||||||
|
prof_handle_room_message(jid->barejid, jid->resourcepart, message);
|
||||||
|
}
|
||||||
|
xmpp_free(ctx, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,6 +324,7 @@ static int
|
|||||||
_chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
_chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata)
|
void * const userdata)
|
||||||
{
|
{
|
||||||
|
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||||
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
Jid *jid = jid_create(from);
|
Jid *jid = jid_create(from);
|
||||||
|
|
||||||
@@ -319,7 +333,10 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
||||||
if (body != NULL) {
|
if (body != NULL) {
|
||||||
char *message = xmpp_stanza_get_text(body);
|
char *message = xmpp_stanza_get_text(body);
|
||||||
prof_handle_duck_result(message);
|
if (message != NULL) {
|
||||||
|
prof_handle_duck_result(message);
|
||||||
|
xmpp_free(ctx, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jid_destroy(jid);
|
jid_destroy(jid);
|
||||||
@@ -335,14 +352,17 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
||||||
if (body != NULL) {
|
if (body != NULL) {
|
||||||
char *message = xmpp_stanza_get_text(body);
|
char *message = xmpp_stanza_get_text(body);
|
||||||
if (delayed) {
|
if (message != NULL) {
|
||||||
prof_handle_delayed_message(jid->str, message, tv_stamp, TRUE);
|
if (delayed) {
|
||||||
} else {
|
prof_handle_delayed_message(jid->str, message, tv_stamp, TRUE);
|
||||||
prof_handle_incoming_message(jid->str, message, TRUE);
|
} else {
|
||||||
|
prof_handle_incoming_message(jid->str, message, TRUE);
|
||||||
|
}
|
||||||
|
xmpp_free(ctx, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(jid);
|
jid_destroy(jid);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// standard chat message, use jid without resource
|
// standard chat message, use jid without resource
|
||||||
@@ -385,14 +405,17 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
||||||
if (body != NULL) {
|
if (body != NULL) {
|
||||||
char *message = xmpp_stanza_get_text(body);
|
char *message = xmpp_stanza_get_text(body);
|
||||||
if (delayed) {
|
if (message != NULL) {
|
||||||
prof_handle_delayed_message(jid->barejid, message, tv_stamp, FALSE);
|
if (delayed) {
|
||||||
} else {
|
prof_handle_delayed_message(jid->barejid, message, tv_stamp, FALSE);
|
||||||
prof_handle_incoming_message(jid->barejid, message, FALSE);
|
} else {
|
||||||
|
prof_handle_incoming_message(jid->barejid, message, FALSE);
|
||||||
|
}
|
||||||
|
xmpp_free(ctx, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(jid);
|
jid_destroy(jid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient,
|
|||||||
xmpp_stanza_set_name(chat_state, state);
|
xmpp_stanza_set_name(chat_state, state);
|
||||||
xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
|
xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
|
||||||
xmpp_stanza_add_child(msg, chat_state);
|
xmpp_stanza_add_child(msg, chat_state);
|
||||||
|
xmpp_stanza_release(chat_state);
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
@@ -75,13 +76,16 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
|
|||||||
text = xmpp_stanza_new(ctx);
|
text = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_text(text, encoded_xml);
|
xmpp_stanza_set_text(text, encoded_xml);
|
||||||
xmpp_stanza_add_child(body, text);
|
xmpp_stanza_add_child(body, text);
|
||||||
|
xmpp_stanza_release(text);
|
||||||
xmpp_stanza_add_child(msg, body);
|
xmpp_stanza_add_child(msg, body);
|
||||||
|
xmpp_stanza_release(body);
|
||||||
|
|
||||||
if (state != NULL) {
|
if (state != NULL) {
|
||||||
xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx);
|
xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(chat_state, state);
|
xmpp_stanza_set_name(chat_state, state);
|
||||||
xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
|
xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
|
||||||
xmpp_stanza_add_child(msg, chat_state);
|
xmpp_stanza_add_child(msg, chat_state);
|
||||||
|
xmpp_stanza_release(chat_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(encoded_xml);
|
g_free(encoded_xml);
|
||||||
@@ -106,7 +110,9 @@ stanza_create_roster_remove_set(xmpp_ctx_t *ctx, const char * const barejid)
|
|||||||
xmpp_stanza_set_attribute(item, STANZA_ATTR_SUBSCRIPTION, "remove");
|
xmpp_stanza_set_attribute(item, STANZA_ATTR_SUBSCRIPTION, "remove");
|
||||||
|
|
||||||
xmpp_stanza_add_child(query, item);
|
xmpp_stanza_add_child(query, item);
|
||||||
|
xmpp_stanza_release(item);
|
||||||
xmpp_stanza_add_child(iq, query);
|
xmpp_stanza_add_child(iq, query);
|
||||||
|
xmpp_stanza_release(query);
|
||||||
|
|
||||||
return iq;
|
return iq;
|
||||||
|
|
||||||
@@ -140,12 +146,16 @@ stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const jid,
|
|||||||
xmpp_stanza_set_name(group, STANZA_NAME_GROUP);
|
xmpp_stanza_set_name(group, STANZA_NAME_GROUP);
|
||||||
xmpp_stanza_set_text(groupname, groups->data);
|
xmpp_stanza_set_text(groupname, groups->data);
|
||||||
xmpp_stanza_add_child(group, groupname);
|
xmpp_stanza_add_child(group, groupname);
|
||||||
|
xmpp_stanza_release(groupname);
|
||||||
xmpp_stanza_add_child(item, group);
|
xmpp_stanza_add_child(item, group);
|
||||||
|
xmpp_stanza_release(group);
|
||||||
groups = g_slist_next(groups);
|
groups = g_slist_next(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
xmpp_stanza_add_child(query, item);
|
xmpp_stanza_add_child(query, item);
|
||||||
|
xmpp_stanza_release(item);
|
||||||
xmpp_stanza_add_child(iq, query);
|
xmpp_stanza_add_child(iq, query);
|
||||||
|
xmpp_stanza_release(query);
|
||||||
|
|
||||||
return iq;
|
return iq;
|
||||||
}
|
}
|
||||||
@@ -170,6 +180,7 @@ stanza_create_invite(xmpp_ctx_t *ctx, const char * const room,
|
|||||||
}
|
}
|
||||||
|
|
||||||
xmpp_stanza_add_child(message, x);
|
xmpp_stanza_add_child(message, x);
|
||||||
|
xmpp_stanza_release(x);
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
@@ -186,6 +197,7 @@ stanza_create_room_join_presence(xmpp_ctx_t * const ctx,
|
|||||||
xmpp_stanza_set_name(x, STANZA_NAME_X);
|
xmpp_stanza_set_name(x, STANZA_NAME_X);
|
||||||
xmpp_stanza_set_ns(x, STANZA_NS_MUC);
|
xmpp_stanza_set_ns(x, STANZA_NS_MUC);
|
||||||
xmpp_stanza_add_child(presence, x);
|
xmpp_stanza_add_child(presence, x);
|
||||||
|
xmpp_stanza_release(x);
|
||||||
|
|
||||||
return presence;
|
return presence;
|
||||||
}
|
}
|
||||||
@@ -704,7 +716,7 @@ stanza_create_form(xmpp_stanza_t * const stanza)
|
|||||||
xmpp_stanza_t *child = xmpp_stanza_get_children(stanza);
|
xmpp_stanza_t *child = xmpp_stanza_get_children(stanza);
|
||||||
|
|
||||||
if (child != NULL) {
|
if (child != NULL) {
|
||||||
result = malloc(sizeof(struct data_form_t));
|
result = malloc(sizeof(DataForm));
|
||||||
result->form_type = NULL;
|
result->form_type = NULL;
|
||||||
result->fields = NULL;
|
result->fields = NULL;
|
||||||
}
|
}
|
||||||
@@ -718,10 +730,11 @@ stanza_create_form(xmpp_stanza_t * const stanza)
|
|||||||
xmpp_stanza_t *value = xmpp_stanza_get_child_by_name(child, "value");
|
xmpp_stanza_t *value = xmpp_stanza_get_child_by_name(child, "value");
|
||||||
char *value_text = xmpp_stanza_get_text(value);
|
char *value_text = xmpp_stanza_get_text(value);
|
||||||
result->form_type = strdup(value_text);
|
result->form_type = strdup(value_text);
|
||||||
|
xmpp_free(ctx, value_text);
|
||||||
|
|
||||||
// handle regular fields
|
// handle regular fields
|
||||||
} else {
|
} else {
|
||||||
FormField *field = malloc(sizeof(struct form_field_t));
|
FormField *field = malloc(sizeof(FormField));
|
||||||
field->var = strdup(var);
|
field->var = strdup(var);
|
||||||
field->values = NULL;
|
field->values = NULL;
|
||||||
xmpp_stanza_t *value = xmpp_stanza_get_children(child);
|
xmpp_stanza_t *value = xmpp_stanza_get_children(child);
|
||||||
@@ -758,10 +771,12 @@ stanza_destroy_form(DataForm *form)
|
|||||||
if ((field->values) != NULL) {
|
if ((field->values) != NULL) {
|
||||||
g_slist_free_full(field->values, free);
|
g_slist_free_full(field->values, free);
|
||||||
}
|
}
|
||||||
|
curr_field = curr_field->next;
|
||||||
}
|
}
|
||||||
|
g_slist_free_full(form->fields, free);
|
||||||
}
|
}
|
||||||
|
|
||||||
form = NULL;
|
free(form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,6 +794,7 @@ stanza_attach_priority(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence,
|
|||||||
xmpp_stanza_set_name(priority, STANZA_NAME_PRIORITY);
|
xmpp_stanza_set_name(priority, STANZA_NAME_PRIORITY);
|
||||||
xmpp_stanza_set_text(value, pri_str);
|
xmpp_stanza_set_text(value, pri_str);
|
||||||
xmpp_stanza_add_child(priority, value);
|
xmpp_stanza_add_child(priority, value);
|
||||||
|
xmpp_stanza_release(value);
|
||||||
xmpp_stanza_add_child(presence, priority);
|
xmpp_stanza_add_child(presence, priority);
|
||||||
xmpp_stanza_release(priority);
|
xmpp_stanza_release(priority);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user