jcs
/wallops
/amendments
/33
*: Use xfree, malloc notes
jcs made amendment 33 over 2 years ago
--- chatter.c Thu Feb 10 13:09:59 2022
+++ chatter.c Tue Sep 6 13:11:16 2022
@@ -52,17 +52,17 @@ chatter_init(const char *server, const unsigned short
if (_TCPInit() != 0)
panic("TCPInit failed");
- chatter = xmalloczero(sizeof(struct chatter));
+ chatter = xmalloczero(sizeof(struct chatter), "chatter");
chatter->irc_state = IRC_STATE_UNINITED;
- chatter->irc_hostname = xstrdup(server);
+ chatter->irc_hostname = xstrdup(server, "server");
chatter->irc_port = port;
if (password && password[0])
- chatter->irc_password = xstrdup(password);
- chatter->irc_nick = xstrdup(nick);
- chatter->irc_ident = xstrdup(ident);
- chatter->irc_realname = xstrdup(realname);
+ chatter->irc_password = xstrdup(password, "password");
+ chatter->irc_nick = xstrdup(nick, "nick");
+ chatter->irc_ident = xstrdup(ident, "ident");
+ chatter->irc_realname = xstrdup(realname, "realname");
if (channel && channel[0])
- chatter->irc_channel_autojoin = xstrdup(channel);
+ chatter->irc_channel_autojoin = xstrdup(channel, "chan");
bounds.left = padding;
bounds.top = screenBits.bounds.top + padding +
@@ -85,7 +85,7 @@ chatter_init(const char *server, const unsigned short
bounds.top = bounds.left = 0;
chatter_layout(chatter, true, &bounds);
- focusable = xmalloczero(sizeof(struct focusable));
+ focusable = xmalloczero(sizeof(struct focusable), "focusable");
focusable->win = chatter->win;
focusable->cookie = chatter;
focusable->wait_type = chatter_wait_type;
@@ -477,7 +477,7 @@ chatter_key_down(struct focusable *focusable, EventRec
te = *(chatter->input_te);
HLock(te->hText);
(*(te->hText))[te->teLength] = '\0';
- input = xstrdup(*(te->hText));
+ input = xstrdup(*(te->hText), "input");
TESetText(&k, 0, chatter->input_te);
EraseRect(&te->viewRect);
ValidRect(&te->viewRect);
@@ -485,7 +485,7 @@ chatter_key_down(struct focusable *focusable, EventRec
HUnlock(te->hText);
HUnlock(chatter->input_te);
irc_process_input(chatter, input);
- free(input);
+ xfree(&input);
} else {
TEKey(k, chatter->input_te);
TESelView(chatter->input_te);
--- irc.c Thu Feb 10 13:09:47 2022
+++ irc.c Tue Sep 6 13:14:58 2022
@@ -20,6 +20,7 @@
#include "chatter.h"
#include "irc.h"
+#include "strnatcmp.h"
void irc_init(struct chatter *chatter);
short irc_verify_state(struct chatter *chatter, int state);
@@ -795,15 +796,16 @@ irc_set_active_channel(struct chatter *chatter, char *
{
if (chatter->irc_channel) {
if (chatter->irc_channel->nicks)
- free(chatter->irc_channel->nicks);
- free(chatter->irc_channel);
+ xfree(&chatter->irc_channel->nicks);
+ xfree(&chatter->irc_channel);
chatter->irc_channel = NULL;
}
if (channame == NULL)
chatter_sync_nick_list(chatter, false);
else {
- chatter->irc_channel = xmalloczero(sizeof(struct irc_channel));
+ chatter->irc_channel = xmalloczero(sizeof(struct irc_channel),
+ "channel");
strlcpy(chatter->irc_channel->name, channame,
sizeof(chatter->irc_channel->name));
}
@@ -993,8 +995,8 @@ irc_change_user_nick(struct chatter *chatter, struct i
}
if (strcmp(chatter->irc_nick, user->nick) == 0) {
- free(chatter->irc_nick);
- chatter->irc_nick = xstrdup(nick);
+ xfree(&chatter->irc_nick);
+ chatter->irc_nick = xstrdup(nick, "nick");
chatter_update_titlebar(chatter);
}
}
--- main.c Thu Feb 10 12:58:50 2022
+++ main.c Tue Sep 6 13:11:46 2022
@@ -494,10 +494,8 @@ close_focusable(struct focusable *focusable)
nfocusables--;
if (nfocusables)
focusables = xreallocarray(focusables, sizeof(Ptr), nfocusables);
- else {
- free(focusables);
- focusables = NULL;
- }
+ else
+ xfree(&focusables);
if (nfocusables && focusables[0]->visible)
SelectWindow(focusables[0]->win);