mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
stanza: guard mallocs
If this happens we have more serious problems :-) But anyways..
This commit is contained in:
parent
d23c3dd065
commit
f81ed759f5
158
src/xmpp/iq.c
158
src/xmpp/iq.c
@ -288,11 +288,13 @@ void
|
||||
iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata)
|
||||
{
|
||||
ProfIqHandler* handler = malloc(sizeof(ProfIqHandler));
|
||||
handler->func = func;
|
||||
handler->free_func = free_func;
|
||||
handler->userdata = userdata;
|
||||
if (handler) {
|
||||
handler->func = func;
|
||||
handler->free_func = free_func;
|
||||
handler->userdata = userdata;
|
||||
|
||||
g_hash_table_insert(id_handlers, strdup(id), handler);
|
||||
g_hash_table_insert(id_handlers, strdup(id), handler);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -481,15 +483,17 @@ iq_room_info_request(const char* const room, gboolean display_result)
|
||||
xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, room, NULL);
|
||||
|
||||
ProfRoomInfoData* cb_data = malloc(sizeof(ProfRoomInfoData));
|
||||
cb_data->room = strdup(room);
|
||||
cb_data->display = display_result;
|
||||
if (cb_data) {
|
||||
cb_data->room = strdup(room);
|
||||
cb_data->display = display_result;
|
||||
|
||||
iq_id_handler_add(id, _room_info_response_id_handler, (ProfIqFreeCallback)_iq_free_room_data, cb_data);
|
||||
iq_id_handler_add(id, _room_info_response_id_handler, (ProfIqFreeCallback)_iq_free_room_data, cb_data);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
free(id);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
|
||||
void
|
||||
@ -667,13 +671,15 @@ iq_room_affiliation_list(const char* const room, char* affiliation, bool show_ui
|
||||
const char* id = xmpp_stanza_get_id(iq);
|
||||
|
||||
ProfAffiliationList* affiliation_list = malloc(sizeof(ProfAffiliationList));
|
||||
affiliation_list->affiliation = strdup(affiliation);
|
||||
affiliation_list->show_ui_message = show_ui_message;
|
||||
if (affiliation_list) {
|
||||
affiliation_list->affiliation = strdup(affiliation);
|
||||
affiliation_list->show_ui_message = show_ui_message;
|
||||
|
||||
iq_id_handler_add(id, _room_affiliation_list_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_list, affiliation_list);
|
||||
iq_id_handler_add(id, _room_affiliation_list_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_list, affiliation_list);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -699,13 +705,15 @@ iq_room_affiliation_set(const char* const room, const char* const jid, char* aff
|
||||
const char* id = xmpp_stanza_get_id(iq);
|
||||
|
||||
ProfPrivilegeSet* affiliation_set = malloc(sizeof(struct privilege_set_t));
|
||||
affiliation_set->item = strdup(jid);
|
||||
affiliation_set->privilege = strdup(affiliation);
|
||||
if (affiliation_set) {
|
||||
affiliation_set->item = strdup(jid);
|
||||
affiliation_set->privilege = strdup(affiliation);
|
||||
|
||||
iq_id_handler_add(id, _room_affiliation_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, affiliation_set);
|
||||
iq_id_handler_add(id, _room_affiliation_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, affiliation_set);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -718,13 +726,15 @@ iq_room_role_set(const char* const room, const char* const nick, char* role,
|
||||
const char* id = xmpp_stanza_get_id(iq);
|
||||
|
||||
struct privilege_set_t* role_set = malloc(sizeof(ProfPrivilegeSet));
|
||||
role_set->item = strdup(nick);
|
||||
role_set->privilege = strdup(role);
|
||||
if (role_set) {
|
||||
role_set->item = strdup(nick);
|
||||
role_set->privilege = strdup(role);
|
||||
|
||||
iq_id_handler_add(id, _room_role_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, role_set);
|
||||
iq_id_handler_add(id, _room_role_set_result_id_handler, (ProfIqFreeCallback)_iq_free_affiliation_set, role_set);
|
||||
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
iq_send_stanza(iq);
|
||||
xmpp_stanza_release(iq);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -2162,27 +2172,29 @@ _room_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata
|
||||
if (name || category || type) {
|
||||
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
|
||||
|
||||
if (name) {
|
||||
identity->name = strdup(name);
|
||||
ProfMucWin* mucwin = wins_get_muc(cb_data->room);
|
||||
if (mucwin) {
|
||||
mucwin->room_name = strdup(name);
|
||||
if (identity) {
|
||||
if (name) {
|
||||
identity->name = strdup(name);
|
||||
ProfMucWin* mucwin = wins_get_muc(cb_data->room);
|
||||
if (mucwin) {
|
||||
mucwin->room_name = strdup(name);
|
||||
}
|
||||
} else {
|
||||
identity->name = NULL;
|
||||
}
|
||||
if (category) {
|
||||
identity->category = strdup(category);
|
||||
} else {
|
||||
identity->category = NULL;
|
||||
}
|
||||
if (type) {
|
||||
identity->type = strdup(type);
|
||||
} else {
|
||||
identity->type = NULL;
|
||||
}
|
||||
} else {
|
||||
identity->name = NULL;
|
||||
}
|
||||
if (category) {
|
||||
identity->category = strdup(category);
|
||||
} else {
|
||||
identity->category = NULL;
|
||||
}
|
||||
if (type) {
|
||||
identity->type = strdup(type);
|
||||
} else {
|
||||
identity->type = NULL;
|
||||
}
|
||||
|
||||
identities = g_slist_append(identities, identity);
|
||||
identities = g_slist_append(identities, identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2309,23 +2321,25 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
|
||||
if (name || category || type) {
|
||||
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
|
||||
|
||||
if (name) {
|
||||
identity->name = strdup(name);
|
||||
} else {
|
||||
identity->name = NULL;
|
||||
}
|
||||
if (category) {
|
||||
identity->category = strdup(category);
|
||||
} else {
|
||||
identity->category = NULL;
|
||||
}
|
||||
if (type) {
|
||||
identity->type = strdup(type);
|
||||
} else {
|
||||
identity->type = NULL;
|
||||
}
|
||||
if (identity) {
|
||||
if (name) {
|
||||
identity->name = strdup(name);
|
||||
} else {
|
||||
identity->name = NULL;
|
||||
}
|
||||
if (category) {
|
||||
identity->category = strdup(category);
|
||||
} else {
|
||||
identity->category = NULL;
|
||||
}
|
||||
if (type) {
|
||||
identity->type = strdup(type);
|
||||
} else {
|
||||
identity->type = NULL;
|
||||
}
|
||||
|
||||
identities = g_slist_append(identities, identity);
|
||||
identities = g_slist_append(identities, identity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2491,14 +2505,16 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
|
||||
const char* item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
|
||||
if (item_jid) {
|
||||
DiscoItem* item = malloc(sizeof(struct disco_item_t));
|
||||
item->jid = strdup(item_jid);
|
||||
const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
|
||||
if (item_name) {
|
||||
item->name = strdup(item_name);
|
||||
} else {
|
||||
item->name = NULL;
|
||||
if (item) {
|
||||
item->jid = strdup(item_jid);
|
||||
const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
|
||||
if (item_name) {
|
||||
item->name = strdup(item_name);
|
||||
} else {
|
||||
item->name = NULL;
|
||||
}
|
||||
items = g_slist_append(items, item);
|
||||
}
|
||||
items = g_slist_append(items, item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2578,10 +2594,12 @@ iq_mam_request(ProfChatWin* win)
|
||||
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, datestr, NULL);
|
||||
|
||||
MamRsmUserdata* data = malloc(sizeof(MamRsmUserdata));
|
||||
data->datestr = strdup(datestr);
|
||||
data->barejid = strdup(win->barejid);
|
||||
if (data) {
|
||||
data->datestr = strdup(datestr);
|
||||
data->barejid = strdup(win->barejid);
|
||||
|
||||
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, NULL, data);
|
||||
iq_id_handler_add(xmpp_stanza_get_id(iq), _mam_rsm_id_handler, NULL, data);
|
||||
}
|
||||
|
||||
g_free(datestr);
|
||||
g_date_time_unref(timestamp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user