mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-24 22:26:22 +00:00
fixed memory leaks in presence.c
This commit is contained in:
@@ -224,11 +224,12 @@ _send_room_presence(xmpp_conn_t *conn, xmpp_stanza_t *presence)
|
|||||||
while (rooms != NULL) {
|
while (rooms != NULL) {
|
||||||
const char *room = rooms->data;
|
const char *room = rooms->data;
|
||||||
const char *nick = muc_get_room_nick(room);
|
const char *nick = muc_get_room_nick(room);
|
||||||
const char *full_room_jid = create_fulljid(room, nick);
|
char *full_room_jid = create_fulljid(room, nick);
|
||||||
|
|
||||||
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
|
xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);
|
||||||
log_debug("Sending presence to room: %s", full_room_jid);
|
log_debug("Sending presence to room: %s", full_room_jid);
|
||||||
xmpp_send(conn, presence);
|
xmpp_send(conn, presence);
|
||||||
|
free(full_room_jid);
|
||||||
|
|
||||||
rooms = g_list_next(rooms);
|
rooms = g_list_next(rooms);
|
||||||
}
|
}
|
||||||
@@ -384,6 +385,7 @@ _unavailable_handler(xmpp_conn_t * const conn,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FREE_SET_NULL(status_str);
|
||||||
jid_destroy(my_jid);
|
jid_destroy(my_jid);
|
||||||
jid_destroy(from_jid);
|
jid_destroy(from_jid);
|
||||||
|
|
||||||
@@ -469,6 +471,8 @@ _available_handler(xmpp_conn_t * const conn,
|
|||||||
last_activity);
|
last_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FREE_SET_NULL(status_str);
|
||||||
|
FREE_SET_NULL(show_str);
|
||||||
jid_destroy(my_jid);
|
jid_destroy(my_jid);
|
||||||
jid_destroy(from_jid);
|
jid_destroy(from_jid);
|
||||||
|
|
||||||
@@ -529,7 +533,7 @@ _get_caps_key(xmpp_stanza_t * const stanza)
|
|||||||
|
|
||||||
guint from_hash = g_str_hash(from);
|
guint from_hash = g_str_hash(from);
|
||||||
char from_hash_str[9];
|
char from_hash_str[9];
|
||||||
g_sprintf(from_hash_str, "%08x", from_hash);
|
g_snprintf(from_hash_str, sizeof(from_hash_str), "%08x", from_hash);
|
||||||
caps_key = strdup(from_hash_str);
|
caps_key = strdup(from_hash_str);
|
||||||
GString *id_str = g_string_new("capsreq_");
|
GString *id_str = g_string_new("capsreq_");
|
||||||
g_string_append(id_str, from_hash_str);
|
g_string_append(id_str, from_hash_str);
|
||||||
@@ -626,7 +630,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FREE_SET_NULL(show_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FREE_SET_NULL(status_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
jid_destroy(my_jid);
|
jid_destroy(my_jid);
|
||||||
|
|||||||
@@ -383,26 +383,48 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp)
|
|||||||
char *
|
char *
|
||||||
stanza_get_status(xmpp_stanza_t *stanza, char *def)
|
stanza_get_status(xmpp_stanza_t *stanza, char *def)
|
||||||
{
|
{
|
||||||
|
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *status =
|
xmpp_stanza_t *status =
|
||||||
xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS);
|
xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS);
|
||||||
|
|
||||||
if (status != NULL) {
|
if (status != NULL) {
|
||||||
return xmpp_stanza_get_text(status);
|
// xmpp_free and free may be different functions so convert all to
|
||||||
|
// libc malloc
|
||||||
|
char *s1, *s2 = NULL;
|
||||||
|
s1 = xmpp_stanza_get_text(status);
|
||||||
|
if (s1 != NULL) {
|
||||||
|
s2 = strdup(s1);
|
||||||
|
xmpp_free(ctx, s1);
|
||||||
|
}
|
||||||
|
return s2;
|
||||||
|
} else if (def != NULL) {
|
||||||
|
return strdup(def);
|
||||||
} else {
|
} else {
|
||||||
return def;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
stanza_get_show(xmpp_stanza_t *stanza, char *def)
|
stanza_get_show(xmpp_stanza_t *stanza, char *def)
|
||||||
{
|
{
|
||||||
|
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||||
xmpp_stanza_t *show =
|
xmpp_stanza_t *show =
|
||||||
xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SHOW);
|
xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SHOW);
|
||||||
|
|
||||||
if (show != NULL) {
|
if (show != NULL) {
|
||||||
return xmpp_stanza_get_text(show);
|
// xmpp_free and free may be different functions so convert all to
|
||||||
|
// libc malloc
|
||||||
|
char *s1, *s2 = NULL;
|
||||||
|
s1 = xmpp_stanza_get_text(show);
|
||||||
|
if (s1 != NULL) {
|
||||||
|
s2 = strdup(s1);
|
||||||
|
xmpp_free(ctx, s1);
|
||||||
|
}
|
||||||
|
return s2;
|
||||||
|
} else if (def != NULL) {
|
||||||
|
return strdup(def);
|
||||||
} else {
|
} else {
|
||||||
return def;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,7 +752,7 @@ 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);
|
xmpp_free(ctx, value_text);
|
||||||
|
|
||||||
// handle regular fields
|
// handle regular fields
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user