mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
most FREE_SET_NULL replaced with free
FREE_SET_NULL makes extra assignment of NULL for pointers in stack or dynamic memory that is going to be freed. FREE_SET_NULL is useful for pointers that can be used in future.
This commit is contained in:
parent
6f498d1f69
commit
0346fda0b3
@ -236,13 +236,13 @@ void
|
||||
accounts_free_account(ProfAccount *account)
|
||||
{
|
||||
if (account != NULL) {
|
||||
FREE_SET_NULL(account->name);
|
||||
FREE_SET_NULL(account->jid);
|
||||
FREE_SET_NULL(account->resource);
|
||||
FREE_SET_NULL(account->server);
|
||||
FREE_SET_NULL(account->last_presence);
|
||||
FREE_SET_NULL(account->login_presence);
|
||||
FREE_SET_NULL(account);
|
||||
free(account->name);
|
||||
free(account->jid);
|
||||
free(account->resource);
|
||||
free(account->server);
|
||||
free(account->last_presence);
|
||||
free(account->login_presence);
|
||||
free(account);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,14 +79,9 @@ p_contact_new(const char * const barejid, const char * const name,
|
||||
void
|
||||
p_contact_set_name(const PContact contact, const char * const name)
|
||||
{
|
||||
if (contact->name != NULL) {
|
||||
FREE_SET_NULL(contact->name);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(contact->name);
|
||||
if (name != NULL) {
|
||||
contact->name = strdup(name);
|
||||
} else {
|
||||
FREE_SET_NULL(contact->name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,22 +125,23 @@ p_contact_remove_resource(PContact contact, const char * const resource)
|
||||
void
|
||||
p_contact_free(PContact contact)
|
||||
{
|
||||
FREE_SET_NULL(contact->barejid);
|
||||
FREE_SET_NULL(contact->name);
|
||||
FREE_SET_NULL(contact->subscription);
|
||||
FREE_SET_NULL(contact->offline_message);
|
||||
if (contact != NULL) {
|
||||
free(contact->barejid);
|
||||
free(contact->name);
|
||||
free(contact->subscription);
|
||||
free(contact->offline_message);
|
||||
|
||||
if (contact->groups != NULL) {
|
||||
g_slist_free_full(contact->groups, g_free);
|
||||
if (contact->groups != NULL) {
|
||||
g_slist_free_full(contact->groups, g_free);
|
||||
}
|
||||
|
||||
if (contact->last_activity != NULL) {
|
||||
g_date_time_unref(contact->last_activity);
|
||||
}
|
||||
|
||||
g_hash_table_destroy(contact->available_resources);
|
||||
free(contact);
|
||||
}
|
||||
|
||||
if (contact->last_activity != NULL) {
|
||||
g_date_time_unref(contact->last_activity);
|
||||
}
|
||||
|
||||
g_hash_table_destroy(contact->available_resources);
|
||||
|
||||
FREE_SET_NULL(contact);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
14
src/jid.c
14
src/jid.c
@ -108,13 +108,13 @@ void
|
||||
jid_destroy(Jid *jid)
|
||||
{
|
||||
if (jid != NULL) {
|
||||
GFREE_SET_NULL(jid->str);
|
||||
GFREE_SET_NULL(jid->localpart);
|
||||
GFREE_SET_NULL(jid->domainpart);
|
||||
GFREE_SET_NULL(jid->resourcepart);
|
||||
GFREE_SET_NULL(jid->barejid);
|
||||
GFREE_SET_NULL(jid->fulljid);
|
||||
FREE_SET_NULL(jid);
|
||||
g_free(jid->str);
|
||||
g_free(jid->localpart);
|
||||
g_free(jid->domainpart);
|
||||
g_free(jid->resourcepart);
|
||||
g_free(jid->barejid);
|
||||
g_free(jid->fulljid);
|
||||
free(jid);
|
||||
}
|
||||
}
|
||||
|
||||
|
20
src/muc.c
20
src/muc.c
@ -442,32 +442,20 @@ static void
|
||||
_free_room(ChatRoom *room)
|
||||
{
|
||||
if (room != NULL) {
|
||||
if (room->room != NULL) {
|
||||
g_free(room->room);
|
||||
room->room = NULL;
|
||||
}
|
||||
if (room->nick != NULL) {
|
||||
g_free(room->nick);
|
||||
room->nick = NULL;
|
||||
}
|
||||
if (room->subject != NULL) {
|
||||
g_free(room->subject);
|
||||
room->subject = NULL;
|
||||
}
|
||||
free(room->room);
|
||||
free(room->nick);
|
||||
free(room->subject);
|
||||
if (room->roster != NULL) {
|
||||
g_hash_table_remove_all(room->roster);
|
||||
room->roster = NULL;
|
||||
}
|
||||
if (room->nick_ac != NULL) {
|
||||
autocomplete_free(room->nick_ac);
|
||||
}
|
||||
if (room->nick_changes != NULL) {
|
||||
g_hash_table_remove_all(room->nick_changes);
|
||||
room->nick_changes = NULL;
|
||||
}
|
||||
g_free(room);
|
||||
free(room);
|
||||
}
|
||||
room = NULL;
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -81,9 +81,10 @@ resource_compare_availability(Resource *first, Resource *second)
|
||||
|
||||
void resource_destroy(Resource *resource)
|
||||
{
|
||||
assert(resource != NULL);
|
||||
FREE_SET_NULL(resource->name);
|
||||
FREE_SET_NULL(resource->status);
|
||||
FREE_SET_NULL(resource->caps_str);
|
||||
FREE_SET_NULL(resource);
|
||||
if (resource != NULL) {
|
||||
free(resource->name);
|
||||
free(resource->status);
|
||||
free(resource->caps_str);
|
||||
free(resource);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "tools/autocomplete.h"
|
||||
#include "tools/parser.h"
|
||||
|
||||
@ -59,10 +60,7 @@ void
|
||||
autocomplete_reset(Autocomplete ac)
|
||||
{
|
||||
ac->last_found = NULL;
|
||||
if (ac->search_str != NULL) {
|
||||
free(ac->search_str);
|
||||
ac->search_str = NULL;
|
||||
}
|
||||
FREE_SET_NULL(ac->search_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -784,7 +784,7 @@ cons_show_room_invite(const char * const invitor, const char * const room,
|
||||
notify_invite(display_from, room, reason);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(display_from);
|
||||
free(display_from);
|
||||
|
||||
ui_console_dirty();
|
||||
cons_alert();
|
||||
|
@ -293,8 +293,9 @@ ui_incoming_msg(const char * const from, const char * const message,
|
||||
GTimeVal *tv_stamp, gboolean priv)
|
||||
{
|
||||
gboolean win_created = FALSE;
|
||||
char *display_from;
|
||||
char *display_from = NULL;
|
||||
win_type_t win_type;
|
||||
|
||||
if (priv) {
|
||||
win_type = WIN_PRIVATE;
|
||||
display_from = get_nick_from_full_jid(from);
|
||||
@ -436,7 +437,7 @@ ui_incoming_msg(const char * const from, const char * const message,
|
||||
if (prefs_get_boolean(PREF_NOTIFY_MESSAGE))
|
||||
notify_message(display_from, ui_index);
|
||||
|
||||
FREE_SET_NULL(display_from);
|
||||
free(display_from);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -301,17 +301,16 @@ static void
|
||||
_caps_destroy(Capabilities *caps)
|
||||
{
|
||||
if (caps != NULL) {
|
||||
FREE_SET_NULL(caps->category);
|
||||
FREE_SET_NULL(caps->type);
|
||||
FREE_SET_NULL(caps->name);
|
||||
FREE_SET_NULL(caps->software);
|
||||
FREE_SET_NULL(caps->software_version);
|
||||
FREE_SET_NULL(caps->os);
|
||||
FREE_SET_NULL(caps->os_version);
|
||||
free(caps->category);
|
||||
free(caps->type);
|
||||
free(caps->name);
|
||||
free(caps->software);
|
||||
free(caps->software_version);
|
||||
free(caps->os);
|
||||
free(caps->os_version);
|
||||
if (caps->features != NULL) {
|
||||
g_slist_free_full(caps->features, free);
|
||||
caps->features = NULL;
|
||||
}
|
||||
FREE_SET_NULL(caps);
|
||||
free(caps);
|
||||
}
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ _unavailable_handler(xmpp_conn_t * const conn,
|
||||
}
|
||||
}
|
||||
|
||||
FREE_SET_NULL(status_str);
|
||||
free(status_str);
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
|
||||
@ -471,8 +471,8 @@ _available_handler(xmpp_conn_t * const conn,
|
||||
last_activity);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(status_str);
|
||||
FREE_SET_NULL(show_str);
|
||||
free(status_str);
|
||||
free(show_str);
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
|
||||
@ -556,10 +556,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *jid = xmpp_conn_get_jid(conn);
|
||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
Jid *my_jid = jid_create(jid);
|
||||
Jid *from_jid = jid_create(from);
|
||||
if (from_jid == NULL || from_jid->resourcepart == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *room = from_jid->barejid;
|
||||
char *nick = from_jid->resourcepart;
|
||||
@ -592,7 +593,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
// handle presence from room members
|
||||
} else {
|
||||
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
||||
char *show_str, *status_str;
|
||||
char *status_str;
|
||||
|
||||
char *caps_key = NULL;
|
||||
if (stanza_contains_caps(stanza)) {
|
||||
@ -608,12 +609,15 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
// handle nickname change
|
||||
if (stanza_is_room_nick_change(stanza)) {
|
||||
char *new_nick = stanza_get_new_nick(stanza);
|
||||
muc_set_roster_pending_nick_change(room, new_nick, nick);
|
||||
if (new_nick != NULL) {
|
||||
muc_set_roster_pending_nick_change(room, new_nick, nick);
|
||||
free(new_nick);
|
||||
}
|
||||
} else {
|
||||
prof_handle_room_member_offline(room, nick, "offline", status_str);
|
||||
}
|
||||
} else {
|
||||
show_str = stanza_get_show(stanza, "online");
|
||||
char *show_str = stanza_get_show(stanza, "online");
|
||||
if (!muc_get_roster_received(room)) {
|
||||
muc_add_to_roster(room, nick, show_str, status_str, caps_key);
|
||||
} else {
|
||||
@ -631,13 +635,13 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
}
|
||||
}
|
||||
|
||||
FREE_SET_NULL(show_str);
|
||||
free(show_str);
|
||||
}
|
||||
|
||||
FREE_SET_NULL(status_str);
|
||||
free(status_str);
|
||||
free(caps_key);
|
||||
}
|
||||
|
||||
jid_destroy(my_jid);
|
||||
jid_destroy(from_jid);
|
||||
|
||||
return 1;
|
||||
|
@ -140,7 +140,7 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
|
||||
xmpp_stanza_set_name(chat_state, state);
|
||||
xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
|
||||
xmpp_stanza_add_child(msg, chat_state);
|
||||
xmpp_stanza_release(chat_state);
|
||||
xmpp_stanza_release(chat_state);
|
||||
}
|
||||
|
||||
return msg;
|
||||
@ -840,12 +840,11 @@ void
|
||||
stanza_destroy_form(DataForm *form)
|
||||
{
|
||||
if (form != NULL) {
|
||||
FREE_SET_NULL(form->form_type);
|
||||
if (form->fields != NULL) {
|
||||
GSList *curr_field = form->fields;
|
||||
while (curr_field != NULL) {
|
||||
FormField *field = curr_field->data;
|
||||
FREE_SET_NULL(field->var);
|
||||
free(field->var);
|
||||
if ((field->values) != NULL) {
|
||||
g_slist_free_full(field->values, free);
|
||||
}
|
||||
@ -854,6 +853,7 @@ stanza_destroy_form(DataForm *form)
|
||||
g_slist_free_full(form->fields, free);
|
||||
}
|
||||
|
||||
free(form->form_type);
|
||||
free(form);
|
||||
}
|
||||
}
|
||||
@ -941,7 +941,7 @@ stanza_attach_caps(xmpp_ctx_t * const ctx, xmpp_stanza_t * const presence)
|
||||
xmpp_stanza_add_child(presence, caps);
|
||||
xmpp_stanza_release(caps);
|
||||
xmpp_stanza_release(query);
|
||||
FREE_SET_NULL(sha1);
|
||||
g_free(sha1);
|
||||
}
|
||||
|
||||
const char *
|
||||
|
Loading…
Reference in New Issue
Block a user