mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -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)
|
accounts_free_account(ProfAccount *account)
|
||||||
{
|
{
|
||||||
if (account != NULL) {
|
if (account != NULL) {
|
||||||
FREE_SET_NULL(account->name);
|
free(account->name);
|
||||||
FREE_SET_NULL(account->jid);
|
free(account->jid);
|
||||||
FREE_SET_NULL(account->resource);
|
free(account->resource);
|
||||||
FREE_SET_NULL(account->server);
|
free(account->server);
|
||||||
FREE_SET_NULL(account->last_presence);
|
free(account->last_presence);
|
||||||
FREE_SET_NULL(account->login_presence);
|
free(account->login_presence);
|
||||||
FREE_SET_NULL(account);
|
free(account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,14 +79,9 @@ p_contact_new(const char * const barejid, const char * const name,
|
|||||||
void
|
void
|
||||||
p_contact_set_name(const PContact contact, const char * const name)
|
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) {
|
if (name != NULL) {
|
||||||
contact->name = strdup(name);
|
contact->name = strdup(name);
|
||||||
} else {
|
|
||||||
FREE_SET_NULL(contact->name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,10 +125,11 @@ p_contact_remove_resource(PContact contact, const char * const resource)
|
|||||||
void
|
void
|
||||||
p_contact_free(PContact contact)
|
p_contact_free(PContact contact)
|
||||||
{
|
{
|
||||||
FREE_SET_NULL(contact->barejid);
|
if (contact != NULL) {
|
||||||
FREE_SET_NULL(contact->name);
|
free(contact->barejid);
|
||||||
FREE_SET_NULL(contact->subscription);
|
free(contact->name);
|
||||||
FREE_SET_NULL(contact->offline_message);
|
free(contact->subscription);
|
||||||
|
free(contact->offline_message);
|
||||||
|
|
||||||
if (contact->groups != NULL) {
|
if (contact->groups != NULL) {
|
||||||
g_slist_free_full(contact->groups, g_free);
|
g_slist_free_full(contact->groups, g_free);
|
||||||
@ -144,8 +140,8 @@ p_contact_free(PContact contact)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_hash_table_destroy(contact->available_resources);
|
g_hash_table_destroy(contact->available_resources);
|
||||||
|
free(contact);
|
||||||
FREE_SET_NULL(contact);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
14
src/jid.c
14
src/jid.c
@ -108,13 +108,13 @@ void
|
|||||||
jid_destroy(Jid *jid)
|
jid_destroy(Jid *jid)
|
||||||
{
|
{
|
||||||
if (jid != NULL) {
|
if (jid != NULL) {
|
||||||
GFREE_SET_NULL(jid->str);
|
g_free(jid->str);
|
||||||
GFREE_SET_NULL(jid->localpart);
|
g_free(jid->localpart);
|
||||||
GFREE_SET_NULL(jid->domainpart);
|
g_free(jid->domainpart);
|
||||||
GFREE_SET_NULL(jid->resourcepart);
|
g_free(jid->resourcepart);
|
||||||
GFREE_SET_NULL(jid->barejid);
|
g_free(jid->barejid);
|
||||||
GFREE_SET_NULL(jid->fulljid);
|
g_free(jid->fulljid);
|
||||||
FREE_SET_NULL(jid);
|
free(jid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
src/muc.c
20
src/muc.c
@ -442,32 +442,20 @@ static void
|
|||||||
_free_room(ChatRoom *room)
|
_free_room(ChatRoom *room)
|
||||||
{
|
{
|
||||||
if (room != NULL) {
|
if (room != NULL) {
|
||||||
if (room->room != NULL) {
|
free(room->room);
|
||||||
g_free(room->room);
|
free(room->nick);
|
||||||
room->room = NULL;
|
free(room->subject);
|
||||||
}
|
|
||||||
if (room->nick != NULL) {
|
|
||||||
g_free(room->nick);
|
|
||||||
room->nick = NULL;
|
|
||||||
}
|
|
||||||
if (room->subject != NULL) {
|
|
||||||
g_free(room->subject);
|
|
||||||
room->subject = NULL;
|
|
||||||
}
|
|
||||||
if (room->roster != NULL) {
|
if (room->roster != NULL) {
|
||||||
g_hash_table_remove_all(room->roster);
|
g_hash_table_remove_all(room->roster);
|
||||||
room->roster = NULL;
|
|
||||||
}
|
}
|
||||||
if (room->nick_ac != NULL) {
|
if (room->nick_ac != NULL) {
|
||||||
autocomplete_free(room->nick_ac);
|
autocomplete_free(room->nick_ac);
|
||||||
}
|
}
|
||||||
if (room->nick_changes != NULL) {
|
if (room->nick_changes != NULL) {
|
||||||
g_hash_table_remove_all(room->nick_changes);
|
g_hash_table_remove_all(room->nick_changes);
|
||||||
room->nick_changes = NULL;
|
|
||||||
}
|
}
|
||||||
g_free(room);
|
free(room);
|
||||||
}
|
}
|
||||||
room = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -81,9 +81,10 @@ resource_compare_availability(Resource *first, Resource *second)
|
|||||||
|
|
||||||
void resource_destroy(Resource *resource)
|
void resource_destroy(Resource *resource)
|
||||||
{
|
{
|
||||||
assert(resource != NULL);
|
if (resource != NULL) {
|
||||||
FREE_SET_NULL(resource->name);
|
free(resource->name);
|
||||||
FREE_SET_NULL(resource->status);
|
free(resource->status);
|
||||||
FREE_SET_NULL(resource->caps_str);
|
free(resource->caps_str);
|
||||||
FREE_SET_NULL(resource);
|
free(resource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include "tools/autocomplete.h"
|
#include "tools/autocomplete.h"
|
||||||
#include "tools/parser.h"
|
#include "tools/parser.h"
|
||||||
|
|
||||||
@ -59,10 +60,7 @@ void
|
|||||||
autocomplete_reset(Autocomplete ac)
|
autocomplete_reset(Autocomplete ac)
|
||||||
{
|
{
|
||||||
ac->last_found = NULL;
|
ac->last_found = NULL;
|
||||||
if (ac->search_str != NULL) {
|
FREE_SET_NULL(ac->search_str);
|
||||||
free(ac->search_str);
|
|
||||||
ac->search_str = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -784,7 +784,7 @@ cons_show_room_invite(const char * const invitor, const char * const room,
|
|||||||
notify_invite(display_from, room, reason);
|
notify_invite(display_from, room, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
FREE_SET_NULL(display_from);
|
free(display_from);
|
||||||
|
|
||||||
ui_console_dirty();
|
ui_console_dirty();
|
||||||
cons_alert();
|
cons_alert();
|
||||||
|
@ -293,8 +293,9 @@ ui_incoming_msg(const char * const from, const char * const message,
|
|||||||
GTimeVal *tv_stamp, gboolean priv)
|
GTimeVal *tv_stamp, gboolean priv)
|
||||||
{
|
{
|
||||||
gboolean win_created = FALSE;
|
gboolean win_created = FALSE;
|
||||||
char *display_from;
|
char *display_from = NULL;
|
||||||
win_type_t win_type;
|
win_type_t win_type;
|
||||||
|
|
||||||
if (priv) {
|
if (priv) {
|
||||||
win_type = WIN_PRIVATE;
|
win_type = WIN_PRIVATE;
|
||||||
display_from = get_nick_from_full_jid(from);
|
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))
|
if (prefs_get_boolean(PREF_NOTIFY_MESSAGE))
|
||||||
notify_message(display_from, ui_index);
|
notify_message(display_from, ui_index);
|
||||||
|
|
||||||
FREE_SET_NULL(display_from);
|
free(display_from);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -301,17 +301,16 @@ static void
|
|||||||
_caps_destroy(Capabilities *caps)
|
_caps_destroy(Capabilities *caps)
|
||||||
{
|
{
|
||||||
if (caps != NULL) {
|
if (caps != NULL) {
|
||||||
FREE_SET_NULL(caps->category);
|
free(caps->category);
|
||||||
FREE_SET_NULL(caps->type);
|
free(caps->type);
|
||||||
FREE_SET_NULL(caps->name);
|
free(caps->name);
|
||||||
FREE_SET_NULL(caps->software);
|
free(caps->software);
|
||||||
FREE_SET_NULL(caps->software_version);
|
free(caps->software_version);
|
||||||
FREE_SET_NULL(caps->os);
|
free(caps->os);
|
||||||
FREE_SET_NULL(caps->os_version);
|
free(caps->os_version);
|
||||||
if (caps->features != NULL) {
|
if (caps->features != NULL) {
|
||||||
g_slist_free_full(caps->features, free);
|
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(my_jid);
|
||||||
jid_destroy(from_jid);
|
jid_destroy(from_jid);
|
||||||
|
|
||||||
@ -471,8 +471,8 @@ _available_handler(xmpp_conn_t * const conn,
|
|||||||
last_activity);
|
last_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
FREE_SET_NULL(status_str);
|
free(status_str);
|
||||||
FREE_SET_NULL(show_str);
|
free(show_str);
|
||||||
jid_destroy(my_jid);
|
jid_destroy(my_jid);
|
||||||
jid_destroy(from_jid);
|
jid_destroy(from_jid);
|
||||||
|
|
||||||
@ -556,10 +556,11 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *jid = xmpp_conn_get_jid(conn);
|
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||||
Jid *my_jid = jid_create(jid);
|
|
||||||
Jid *from_jid = jid_create(from);
|
Jid *from_jid = jid_create(from);
|
||||||
|
if (from_jid == NULL || from_jid->resourcepart == NULL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
char *room = from_jid->barejid;
|
char *room = from_jid->barejid;
|
||||||
char *nick = from_jid->resourcepart;
|
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
|
// handle presence from room members
|
||||||
} else {
|
} else {
|
||||||
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
||||||
char *show_str, *status_str;
|
char *status_str;
|
||||||
|
|
||||||
char *caps_key = NULL;
|
char *caps_key = NULL;
|
||||||
if (stanza_contains_caps(stanza)) {
|
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
|
// handle nickname change
|
||||||
if (stanza_is_room_nick_change(stanza)) {
|
if (stanza_is_room_nick_change(stanza)) {
|
||||||
char *new_nick = stanza_get_new_nick(stanza);
|
char *new_nick = stanza_get_new_nick(stanza);
|
||||||
|
if (new_nick != NULL) {
|
||||||
muc_set_roster_pending_nick_change(room, new_nick, nick);
|
muc_set_roster_pending_nick_change(room, new_nick, nick);
|
||||||
|
free(new_nick);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
prof_handle_room_member_offline(room, nick, "offline", status_str);
|
prof_handle_room_member_offline(room, nick, "offline", status_str);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
show_str = stanza_get_show(stanza, "online");
|
char *show_str = stanza_get_show(stanza, "online");
|
||||||
if (!muc_get_roster_received(room)) {
|
if (!muc_get_roster_received(room)) {
|
||||||
muc_add_to_roster(room, nick, show_str, status_str, caps_key);
|
muc_add_to_roster(room, nick, show_str, status_str, caps_key);
|
||||||
} else {
|
} 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);
|
jid_destroy(from_jid);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -840,12 +840,11 @@ void
|
|||||||
stanza_destroy_form(DataForm *form)
|
stanza_destroy_form(DataForm *form)
|
||||||
{
|
{
|
||||||
if (form != NULL) {
|
if (form != NULL) {
|
||||||
FREE_SET_NULL(form->form_type);
|
|
||||||
if (form->fields != NULL) {
|
if (form->fields != NULL) {
|
||||||
GSList *curr_field = form->fields;
|
GSList *curr_field = form->fields;
|
||||||
while (curr_field != NULL) {
|
while (curr_field != NULL) {
|
||||||
FormField *field = curr_field->data;
|
FormField *field = curr_field->data;
|
||||||
FREE_SET_NULL(field->var);
|
free(field->var);
|
||||||
if ((field->values) != NULL) {
|
if ((field->values) != NULL) {
|
||||||
g_slist_free_full(field->values, free);
|
g_slist_free_full(field->values, free);
|
||||||
}
|
}
|
||||||
@ -854,6 +853,7 @@ stanza_destroy_form(DataForm *form)
|
|||||||
g_slist_free_full(form->fields, free);
|
g_slist_free_full(form->fields, free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(form->form_type);
|
||||||
free(form);
|
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_add_child(presence, caps);
|
||||||
xmpp_stanza_release(caps);
|
xmpp_stanza_release(caps);
|
||||||
xmpp_stanza_release(query);
|
xmpp_stanza_release(query);
|
||||||
FREE_SET_NULL(sha1);
|
g_free(sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
Loading…
Reference in New Issue
Block a user