1
0
mirror of https://github.com/moparisthebest/hexchat synced 2024-11-22 09:12:22 -05:00

Use glib for all allocations

- Removes need to check for malloc failure
- Removes need for NULL checks on free
- Adds checks for integer overflows
- Removes some extra memset calls
- Removes chance of mixing libc and glib malloc/free
This commit is contained in:
TingPing 2014-12-28 06:37:25 -05:00
parent c4cb1b25ec
commit 83032b1aa3
46 changed files with 796 additions and 1082 deletions

View File

@ -61,7 +61,7 @@ list_addentry (GSList ** list, char *cmd, char *name)
cmd_len = strlen (cmd) + 1; cmd_len = strlen (cmd) + 1;
name_len = strlen (name) + 1; name_len = strlen (name) + 1;
pop = malloc (sizeof (struct popup) + cmd_len + name_len); pop = g_malloc (sizeof (struct popup) + cmd_len + name_len);
pop->name = (char *) pop + sizeof (struct popup); pop->name = (char *) pop + sizeof (struct popup);
pop->cmd = pop->name + name_len; pop->cmd = pop->name + name_len;
@ -133,13 +133,13 @@ list_loadconf (char *file, GSList ** list, char *defaultconf)
abort (); abort ();
} }
ibuf = malloc (st.st_size); ibuf = g_malloc (st.st_size);
read (fd, ibuf, st.st_size); read (fd, ibuf, st.st_size);
close (fd); close (fd);
list_load_from_data (list, ibuf, st.st_size); list_load_from_data (list, ibuf, st.st_size);
free (ibuf); g_free (ibuf);
} }
void void
@ -149,7 +149,7 @@ list_free (GSList ** list)
while (*list) while (*list)
{ {
data = (void *) (*list)->data; data = (void *) (*list)->data;
free (data); g_free (data);
*list = g_slist_remove (*list, data); *list = g_slist_remove (*list, data);
} }
} }
@ -166,7 +166,7 @@ list_delentry (GSList ** list, char *name)
if (!g_ascii_strcasecmp (name, pop->name)) if (!g_ascii_strcasecmp (name, pop->name))
{ {
*list = g_slist_remove (*list, pop); *list = g_slist_remove (*list, pop);
free (pop); g_free (pop);
return 1; return 1;
} }
alist = alist->next; alist = alist->next;
@ -647,7 +647,7 @@ get_default_language (void)
if (lang_no >= 0) if (lang_no >= 0)
{ {
free (lang); g_free (lang);
return lang_no; return lang_no;
} }
@ -656,7 +656,7 @@ get_default_language (void)
lang_no = find_language_number (lang); lang_no = find_language_number (lang);
free (lang); g_free (lang);
return lang_no >= 0 ? lang_no : find_language_number ("en"); return lang_no >= 0 ? lang_no : find_language_number ("en");
} }
@ -1226,7 +1226,7 @@ cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (erase || *val) if (erase || *val)
{ {
/* save the previous value until we print it out */ /* save the previous value until we print it out */
prev_string = (char*) malloc (vars[i].len + 1); prev_string = g_malloc (vars[i].len + 1);
strncpy (prev_string, (char *) &prefs + vars[i].offset, vars[i].len); strncpy (prev_string, (char *) &prefs + vars[i].offset, vars[i].len);
/* update the variable */ /* update the variable */
@ -1238,7 +1238,7 @@ cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[])
PrintTextf (sess, "%s set to: %s (was: %s)\n", var, (char *) &prefs + vars[i].offset, prev_string); PrintTextf (sess, "%s set to: %s (was: %s)\n", var, (char *) &prefs + vars[i].offset, prev_string);
} }
free (prev_string); g_free (prev_string);
} }
else else
{ {

View File

@ -208,7 +208,7 @@ chanopt_find (char *network, char *channel, gboolean add_new)
return NULL; return NULL;
/* allocate a new one */ /* allocate a new one */
co = g_malloc0 (sizeof (chanopt_in_memory)); co = g_new0 (chanopt_in_memory, 1);
co->channel = g_strdup (channel); co->channel = g_strdup (channel);
co->network = g_strdup (network); co->network = g_strdup (network);

View File

@ -44,12 +44,12 @@ ctcp_reply (session *sess, char *nick, char *word[], char *word_eol[],
{ {
char tbuf[4096]; /* can receive 2048 from IRC, so this is enough */ char tbuf[4096]; /* can receive 2048 from IRC, so this is enough */
conf = strdup (conf); conf = g_strdup (conf);
/* process %C %B etc */ /* process %C %B etc */
check_special_chars (conf, TRUE); check_special_chars (conf, TRUE);
auto_insert (tbuf, sizeof (tbuf), conf, word, word_eol, "", "", word_eol[5], auto_insert (tbuf, sizeof (tbuf), conf, word, word_eol, "", "", word_eol[5],
server_get_network (sess->server, TRUE), "", "", nick, ""); server_get_network (sess->server, TRUE), "", "", nick, "");
free (conf); g_free (conf);
handle_command (sess, tbuf, FALSE); handle_command (sess, tbuf, FALSE);
} }

View File

@ -309,7 +309,7 @@ dcc_lookup_proxy (char *host, struct sockaddr_in *addr)
memcpy (&addr->sin_addr, &cache_addr, 4); memcpy (&addr->sin_addr, &cache_addr, 4);
return TRUE; return TRUE;
} }
free (cache_host); g_free (cache_host);
cache_host = NULL; cache_host = NULL;
} }
@ -318,7 +318,7 @@ dcc_lookup_proxy (char *host, struct sockaddr_in *addr)
{ {
memcpy (&addr->sin_addr, h->h_addr, 4); memcpy (&addr->sin_addr, h->h_addr, 4);
memcpy (&cache_addr, h->h_addr, 4); memcpy (&cache_addr, h->h_addr, 4);
cache_host = strdup (host); cache_host = g_strdup (host);
/* cppcheck-suppress memleak */ /* cppcheck-suppress memleak */
return TRUE; return TRUE;
} }
@ -406,7 +406,7 @@ dcc_close (struct DCC *dcc, int dccstat, int destroy)
dcc->dccstat = dccstat; dcc->dccstat = dccstat;
if (dcc->dccchat) if (dcc->dccchat)
{ {
free (dcc->dccchat); g_free (dcc->dccchat);
dcc->dccchat = NULL; dcc->dccchat = NULL;
} }
@ -417,7 +417,7 @@ dcc_close (struct DCC *dcc, int dccstat, int destroy)
g_free (dcc->proxy); g_free (dcc->proxy);
g_free (dcc->file); g_free (dcc->file);
g_free (dcc->destfile); g_free (dcc->destfile);
free (dcc->nick); g_free (dcc->nick);
g_free (dcc); g_free (dcc);
return; return;
} }
@ -888,8 +888,7 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
dcc_open_query (dcc->serv, dcc->nick); dcc_open_query (dcc->serv, dcc->nick);
case TYPE_CHATRECV: /* normal chat */ case TYPE_CHATRECV: /* normal chat */
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc); dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
dcc->dccchat = malloc (sizeof (struct dcc_chat)); dcc->dccchat = g_new0 (struct dcc_chat, 1);
dcc->dccchat->pos = 0;
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
dcc->nick, host, NULL, NULL, 0); dcc->nick, host, NULL, NULL, 0);
break; break;
@ -1369,12 +1368,6 @@ dcc_proxy_connect (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
return TRUE; return TRUE;
dcc->proxy = g_new0 (struct proxy_state, 1); dcc->proxy = g_new0 (struct proxy_state, 1);
if (!dcc->proxy)
{
dcc->dccstat = STAT_FAILED;
fe_dcc_update (dcc);
return TRUE;
}
switch (prefs.hex_net_proxy_type) switch (prefs.hex_net_proxy_type)
{ {
@ -1463,9 +1456,7 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
else if (!dcc->wiotag) else if (!dcc->wiotag)
dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc); dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc);
buf = malloc (prefs.hex_dcc_blocksize); buf = g_malloc (prefs.hex_dcc_blocksize);
if (!buf)
return TRUE;
lseek (dcc->fp, dcc->pos, SEEK_SET); lseek (dcc->fp, dcc->pos, SEEK_SET);
len = read (dcc->fp, buf, prefs.hex_dcc_blocksize); len = read (dcc->fp, buf, prefs.hex_dcc_blocksize);
@ -1476,7 +1467,7 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
if (sent < 0 && !(would_block ())) if (sent < 0 && !(would_block ()))
{ {
abortit: abortit:
free (buf); g_free (buf);
EMIT_SIGNAL (XP_TE_DCCSENDFAIL, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCSENDFAIL, dcc->serv->front_session,
file_part (dcc->file), dcc->nick, file_part (dcc->file), dcc->nick,
errorstring (sock_error ()), NULL, 0); errorstring (sock_error ()), NULL, 0);
@ -1500,7 +1491,7 @@ abortit:
} }
} }
free (buf); g_free (buf);
return TRUE; return TRUE;
} }
@ -1630,8 +1621,7 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
case TYPE_CHATSEND: case TYPE_CHATSEND:
dcc_open_query (dcc->serv, dcc->nick); dcc_open_query (dcc->serv, dcc->nick);
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc); dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
dcc->dccchat = malloc (sizeof (struct dcc_chat)); dcc->dccchat = g_new0 (struct dcc_chat, 1);
dcc->dccchat->pos = 0;
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session, EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
dcc->nick, host, NULL, NULL, 0); dcc->nick, host, NULL, NULL, 0);
break; break;
@ -1897,7 +1887,7 @@ dcc_send (struct session *sess, char *to, char *filename, gint64 maxcps, int pas
} }
filename++; filename++;
} }
dcc->nick = strdup (to); dcc->nick = g_strdup (to);
if (prefs.hex_gui_autoopen_send) if (prefs.hex_gui_autoopen_send)
{ {
if (fe_dcc_open_send_win (TRUE)) /* already open? add */ if (fe_dcc_open_send_win (TRUE)) /* already open? add */
@ -2005,9 +1995,8 @@ dcc_change_nick (struct server *serv, char *oldnick, char *newnick)
{ {
if (!serv->p_cmp (dcc->nick, oldnick)) if (!serv->p_cmp (dcc->nick, oldnick))
{ {
if (dcc->nick) g_free (dcc->nick);
free (dcc->nick); dcc->nick = g_strdup (newnick);
dcc->nick = strdup (newnick);
} }
} }
list = list->next; list = list->next;
@ -2257,11 +2246,6 @@ static struct DCC *
new_dcc (void) new_dcc (void)
{ {
struct DCC *dcc = g_new0 (struct DCC, 1); struct DCC *dcc = g_new0 (struct DCC, 1);
if (!dcc)
{
return NULL;
}
dcc->sok = -1; dcc->sok = -1;
dcc->fp = -1; dcc->fp = -1;
dcc_list = g_slist_prepend (dcc_list, dcc); dcc_list = g_slist_prepend (dcc_list, dcc);
@ -2312,7 +2296,7 @@ dcc_chat (struct session *sess, char *nick, int passive)
dcc->serv = sess->server; dcc->serv = sess->server;
dcc->dccstat = STAT_QUEUED; dcc->dccstat = STAT_QUEUED;
dcc->type = TYPE_CHATSEND; dcc->type = TYPE_CHATSEND;
dcc->nick = strdup (nick); dcc->nick = g_strdup (nick);
if (passive || dcc_listen_init (dcc, sess)) if (passive || dcc_listen_init (dcc, sess))
{ {
if (prefs.hex_gui_autoopen_chat) if (prefs.hex_gui_autoopen_chat)
@ -2412,7 +2396,7 @@ dcc_add_chat (session *sess, char *nick, int port, guint32 addr, int pasvid)
dcc->addr = addr; dcc->addr = addr;
dcc->port = port; dcc->port = port;
dcc->pasvid = pasvid; dcc->pasvid = pasvid;
dcc->nick = strdup (nick); dcc->nick = g_strdup (nick);
dcc->starttime = time (0); dcc->starttime = time (0);
EMIT_SIGNAL (XP_TE_DCCCHATOFFER, sess->server->front_session, nick, EMIT_SIGNAL (XP_TE_DCCCHATOFFER, sess->server->front_session, nick,
@ -2484,7 +2468,7 @@ dcc_add_file (session *sess, char *file, guint64 size, int port, char *nick, gui
dcc->port = port; dcc->port = port;
dcc->pasvid = pasvid; dcc->pasvid = pasvid;
dcc->size = size; dcc->size = size;
dcc->nick = strdup (nick); dcc->nick = g_strdup (nick);
dcc->maxcps = prefs.hex_dcc_max_get_cps; dcc->maxcps = prefs.hex_dcc_max_get_cps;
update_is_resumable (dcc); update_is_resumable (dcc);

View File

@ -456,12 +456,7 @@ session_new (server *serv, char *from, int type, int focus)
{ {
session *sess; session *sess;
sess = malloc (sizeof (struct session)); sess = g_new0 (struct session, 1);
if (sess == NULL)
{
return NULL;
}
memset (sess, 0, sizeof (struct session));
sess->server = serv; sess->server = serv;
sess->logfd = -1; sess->logfd = -1;
@ -543,9 +538,8 @@ exec_notify_kill (session * sess)
waitpid (re->childpid, NULL, WNOHANG); waitpid (re->childpid, NULL, WNOHANG);
fe_input_remove (re->iotag); fe_input_remove (re->iotag);
close (re->myfd); close (re->myfd);
if (re->linebuf) g_free(re->linebuf);
free(re->linebuf); g_free (re);
free (re);
} }
#endif #endif
} }
@ -651,10 +645,8 @@ session_free (session *killsess)
send_quit_or_part (killsess); send_quit_or_part (killsess);
history_free (&killsess->history); history_free (&killsess->history);
if (killsess->topic) g_free (killsess->topic);
free (killsess->topic); g_free (killsess->current_modes);
if (killsess->current_modes)
free (killsess->current_modes);
fe_session_callback (killsess); fe_session_callback (killsess);
@ -665,7 +657,7 @@ session_free (session *killsess)
current_sess = sess_list->data; current_sess = sess_list->data;
} }
free (killsess); g_free (killsess);
if (!sess_list && !in_hexchat_exit) if (!sess_list && !in_hexchat_exit)
hexchat_exit (); /* sess_list is empty, quit! */ hexchat_exit (); /* sess_list is empty, quit! */
@ -1029,11 +1021,11 @@ main (int argc, char *argv[])
if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0) if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0)
&& i + 1 < argc) && i + 1 < argc)
{ {
xdir = strdup (argv[i + 1]); xdir = g_strdup (argv[i + 1]);
} }
else if (strncmp (argv[i], "--cfgdir=", 9) == 0) else if (strncmp (argv[i], "--cfgdir=", 9) == 0)
{ {
xdir = strdup (argv[i] + 9); xdir = g_strdup (argv[i] + 9);
} }
if (xdir != NULL) if (xdir != NULL)

View File

@ -18,14 +18,14 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <glib.h>
#include "history.h" #include "history.h"
void void
history_add (struct history *his, char *text) history_add (struct history *his, char *text)
{ {
if (his->lines[his->realpos]) g_free (his->lines[his->realpos]);
free (his->lines[his->realpos]); his->lines[his->realpos] = g_strdup (text);
his->lines[his->realpos] = strdup (text);
his->realpos++; his->realpos++;
if (his->realpos == HISTORY_SIZE) if (his->realpos == HISTORY_SIZE)
his->realpos = 0; his->realpos = 0;
@ -40,7 +40,7 @@ history_free (struct history *his)
{ {
if (his->lines[i]) if (his->lines[i])
{ {
free (his->lines[i]); g_free (his->lines[i]);
his->lines[i] = 0; his->lines[i] = 0;
} }
} }

View File

@ -42,7 +42,7 @@ identd (char *username)
sok = socket (AF_INET, SOCK_STREAM, 0); sok = socket (AF_INET, SOCK_STREAM, 0);
if (sok == INVALID_SOCKET) if (sok == INVALID_SOCKET)
{ {
free (username); g_free (username);
return 0; return 0;
} }
@ -56,14 +56,14 @@ identd (char *username)
if (bind (sok, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR) if (bind (sok, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
{ {
closesocket (sok); closesocket (sok);
free (username); g_free (username);
return 0; return 0;
} }
if (listen (sok, 1) == SOCKET_ERROR) if (listen (sok, 1) == SOCKET_ERROR)
{ {
closesocket (sok); closesocket (sok);
free (username); g_free (username);
return 0; return 0;
} }
@ -72,7 +72,7 @@ identd (char *username)
closesocket (sok); closesocket (sok);
if (read_sok == INVALID_SOCKET) if (read_sok == INVALID_SOCKET)
{ {
free (username); g_free (username);
return 0; return 0;
} }
@ -99,7 +99,7 @@ identd (char *username)
sleep (1); sleep (1);
closesocket (read_sok); closesocket (read_sok);
free (username); g_free (username);
return 0; return 0;
} }
@ -118,7 +118,7 @@ identd_ipv6 (char *username)
sok = socket (AF_INET6, SOCK_STREAM, 0); sok = socket (AF_INET6, SOCK_STREAM, 0);
if (sok == INVALID_SOCKET) if (sok == INVALID_SOCKET)
{ {
free (username); g_free (username);
return 0; return 0;
} }
@ -132,14 +132,14 @@ identd_ipv6 (char *username)
if (bind (sok, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR) if (bind (sok, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
{ {
closesocket (sok); closesocket (sok);
free (username); g_free (username);
return 0; return 0;
} }
if (listen (sok, 1) == SOCKET_ERROR) if (listen (sok, 1) == SOCKET_ERROR)
{ {
closesocket (sok); closesocket (sok);
free (username); g_free (username);
return 0; return 0;
} }
@ -148,7 +148,7 @@ identd_ipv6 (char *username)
closesocket (sok); closesocket (sok);
if (read_sok == INVALID_SOCKET) if (read_sok == INVALID_SOCKET)
{ {
free (username); g_free (username);
return 0; return 0;
} }
@ -171,7 +171,7 @@ identd_ipv6 (char *username)
sleep (1); sleep (1);
closesocket (read_sok); closesocket (read_sok);
free (username); g_free (username);
return 0; return 0;
} }
@ -188,7 +188,7 @@ identd_start (char *username)
{ {
identd_ipv6_is_running = TRUE; identd_ipv6_is_running = TRUE;
CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) identd_ipv6, CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) identd_ipv6,
strdup (username), 0, &tidv6)); g_strdup (username), 0, &tidv6));
} }
#endif #endif
@ -196,6 +196,6 @@ identd_start (char *username)
{ {
identd_is_running = TRUE; identd_is_running = TRUE;
CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) identd, CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) identd,
strdup (username), 0, &tid)); g_strdup (username), 0, &tid));
} }
} }

View File

@ -53,7 +53,7 @@ static int ignored_total = 0;
struct ignore * struct ignore *
ignore_exists (char *mask) ignore_exists (char *mask)
{ {
struct ignore *ig = 0; struct ignore *ig = NULL;
GSList *list; GSList *list;
list = ignore_list; list = ignore_list;
@ -79,7 +79,7 @@ ignore_exists (char *mask)
int int
ignore_add (char *mask, int type, gboolean overwrite) ignore_add (char *mask, int type, gboolean overwrite)
{ {
struct ignore *ig = 0; struct ignore *ig = NULL;
int change_only = FALSE; int change_only = FALSE;
/* first check if it's already ignored */ /* first check if it's already ignored */
@ -88,12 +88,9 @@ ignore_add (char *mask, int type, gboolean overwrite)
change_only = TRUE; change_only = TRUE;
if (!change_only) if (!change_only)
ig = malloc (sizeof (struct ignore)); ig = g_new (struct ignore, 1);
if (!ig) ig->mask = g_strdup (mask);
return 0;
ig->mask = strdup (mask);
if (!overwrite && change_only) if (!overwrite && change_only)
ig->type |= type; ig->type |= type;
@ -192,8 +189,8 @@ ignore_del (char *mask, struct ignore *ig)
if (ig) if (ig)
{ {
ignore_list = g_slist_remove (ignore_list, ig); ignore_list = g_slist_remove (ignore_list, ig);
free (ig->mask); g_free (ig->mask);
free (ig); g_free (ig);
fe_ignore_update (1); fe_ignore_update (1);
return TRUE; return TRUE;
} }
@ -265,7 +262,7 @@ ignore_read_next_entry (char *my_cfg, struct ignore *ignore)
my_cfg = cfg_get_str (my_cfg, "mask", tbuf, sizeof (tbuf)); my_cfg = cfg_get_str (my_cfg, "mask", tbuf, sizeof (tbuf));
if (!my_cfg) if (!my_cfg)
return NULL; return NULL;
ignore->mask = strdup (tbuf); ignore->mask = g_strdup (tbuf);
} }
if (my_cfg) if (my_cfg)
{ {
@ -281,7 +278,7 @@ ignore_load ()
struct ignore *ignore; struct ignore *ignore;
struct stat st; struct stat st;
char *cfg, *my_cfg; char *cfg, *my_cfg;
int fh, i; int fh;
fh = hexchat_open_file ("ignore.conf", O_RDONLY, 0, 0); fh = hexchat_open_file ("ignore.conf", O_RDONLY, 0, 0);
if (fh != -1) if (fh != -1)
@ -289,22 +286,18 @@ ignore_load ()
fstat (fh, &st); fstat (fh, &st);
if (st.st_size) if (st.st_size)
{ {
cfg = malloc (st.st_size + 1); cfg = g_malloc0 (st.st_size + 1);
cfg[0] = '\0'; read (fh, cfg, st.st_size);
i = read (fh, cfg, st.st_size);
if (i >= 0)
cfg[i] = '\0';
my_cfg = cfg; my_cfg = cfg;
while (my_cfg) while (my_cfg)
{ {
ignore = malloc (sizeof (struct ignore)); ignore = g_new0 (struct ignore, 1);
memset (ignore, 0, sizeof (struct ignore));
if ((my_cfg = ignore_read_next_entry (my_cfg, ignore))) if ((my_cfg = ignore_read_next_entry (my_cfg, ignore)))
ignore_list = g_slist_prepend (ignore_list, ignore); ignore_list = g_slist_prepend (ignore_list, ignore);
else else
free (ignore); g_free (ignore);
} }
free (cfg); g_free (cfg);
} }
close (fh); close (fh);
} }

View File

@ -62,7 +62,7 @@ clear_channel (session *sess)
if (sess->current_modes) if (sess->current_modes)
{ {
free (sess->current_modes); g_free (sess->current_modes);
sess->current_modes = NULL; sess->current_modes = NULL;
} }
@ -81,9 +81,8 @@ clear_channel (session *sess)
void void
set_topic (session *sess, char *topic, char *stripped_topic) set_topic (session *sess, char *topic, char *stripped_topic)
{ {
if (sess->topic) g_free (sess->topic);
free (sess->topic); sess->topic = g_strdup (stripped_topic);
sess->topic = strdup (stripped_topic);
fe_set_topic (sess, topic, stripped_topic); fe_set_topic (sess, topic, stripped_topic);
} }
@ -968,14 +967,14 @@ inbound_notice (server *serv, char *to, char *nick, char *msg, char *ip, int id,
/* guess where chanserv meant to post this -sigh- */ /* guess where chanserv meant to post this -sigh- */
if (!g_ascii_strcasecmp (nick, "ChanServ") && !find_dialog (serv, nick)) if (!g_ascii_strcasecmp (nick, "ChanServ") && !find_dialog (serv, nick))
{ {
char *dest = strdup (msg + 1); char *dest = g_strdup (msg + 1);
char *end = strchr (dest, ']'); char *end = strchr (dest, ']');
if (end) if (end)
{ {
*end = 0; *end = 0;
sess = find_channel (serv, dest); sess = find_channel (serv, dest);
} }
free (dest); g_free (dest);
} }
} }
if (!sess) if (!sess)
@ -1454,8 +1453,7 @@ inbound_user_info (session *sess, char *chan, char *user, char *host,
if (user && host) if (user && host)
{ {
uhost = g_malloc (strlen (user) + strlen (host) + 2); uhost = g_strdup_printf ("%s@%s", user, host);
sprintf (uhost, "%s@%s", user, host);
} }
if (chan) if (chan)

View File

@ -331,7 +331,7 @@ record_chan_mode (session *sess, char sign, char mode, char *arg)
current = g_string_erase(current, argument_offset+1, argument_length-1); current = g_string_erase(current, argument_offset+1, argument_length-1);
current = g_string_insert(current, argument_offset+1, arg); current = g_string_insert(current, argument_offset+1, arg);
free(sess->current_modes); g_free(sess->current_modes);
sess->current_modes = g_string_free(current, FALSE); sess->current_modes = g_string_free(current, FALSE);
} }
} }
@ -348,7 +348,7 @@ record_chan_mode (session *sess, char sign, char mode, char *arg)
current = g_string_append(current, arg); current = g_string_append(current, arg);
} }
free(sess->current_modes); g_free(sess->current_modes);
sess->current_modes = g_string_free(current, FALSE); sess->current_modes = g_string_free(current, FALSE);
} }
} }
@ -361,7 +361,7 @@ record_chan_mode (session *sess, char sign, char mode, char *arg)
/* remove the mode character */ /* remove the mode character */
current = g_string_erase(current, mode_pos, 1); current = g_string_erase(current, mode_pos, 1);
free(sess->current_modes); g_free(sess->current_modes);
sess->current_modes = g_string_free(current, FALSE); sess->current_modes = g_string_free(current, FALSE);
} }
} }
@ -374,12 +374,13 @@ mode_cat (char *str, char *addition)
if (str) if (str)
{ {
len = strlen (str) + strlen (addition) + 2; len = strlen (str) + strlen (addition) + 2;
str = realloc (str, len); str = g_realloc (str, len);
strcat (str, " "); strcat (str, " ");
strcat (str, addition); strcat (str, addition);
} else }
else
{ {
str = strdup (addition); str = g_strdup (addition);
} }
return str; return str;
@ -560,12 +561,12 @@ handle_single_mode (mode_run *mr, char sign, char mode, char *nick,
{ {
if (*arg) if (*arg)
{ {
char *buf = malloc (strlen (chan) + strlen (arg) + 2); char *buf = g_strdup_printf ("%s %s", chan, arg);
sprintf (buf, "%s %s", chan, arg);
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANMODEGEN, sess, nick, outbuf, EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANMODEGEN, sess, nick, outbuf,
outbuf + 2, buf, 0, tags_data->timestamp); outbuf + 2, buf, 0, tags_data->timestamp);
free (buf); g_free (buf);
} else }
else
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANMODEGEN, sess, nick, outbuf, EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANMODEGEN, sess, nick, outbuf,
outbuf + 2, chan, 0, tags_data->timestamp); outbuf + 2, chan, 0, tags_data->timestamp);
} }
@ -635,7 +636,7 @@ mode_print_grouped (session *sess, char *nick, mode_run *mr,
{ {
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANOP, sess, nick, mr->op, NULL, NULL, 0, EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANOP, sess, nick, mr->op, NULL, NULL, 0,
tags_data->timestamp); tags_data->timestamp);
free (mr->op); g_free(mr->op);
mr->op = NULL; mr->op = NULL;
} }
@ -643,7 +644,7 @@ mode_print_grouped (session *sess, char *nick, mode_run *mr,
{ {
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANDEOP, sess, nick, mr->deop, NULL, NULL, EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANDEOP, sess, nick, mr->deop, NULL, NULL,
0, tags_data->timestamp); 0, tags_data->timestamp);
free (mr->deop); g_free(mr->deop);
mr->deop = NULL; mr->deop = NULL;
} }
@ -651,7 +652,7 @@ mode_print_grouped (session *sess, char *nick, mode_run *mr,
{ {
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANVOICE, sess, nick, mr->voice, NULL, NULL, EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANVOICE, sess, nick, mr->voice, NULL, NULL,
0, tags_data->timestamp); 0, tags_data->timestamp);
free (mr->voice); g_free(mr->voice);
mr->voice = NULL; mr->voice = NULL;
} }
@ -659,7 +660,7 @@ mode_print_grouped (session *sess, char *nick, mode_run *mr,
{ {
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANDEVOICE, sess, nick, mr->devoice, NULL, EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANDEVOICE, sess, nick, mr->devoice, NULL,
NULL, 0, tags_data->timestamp); NULL, 0, tags_data->timestamp);
free (mr->devoice); g_free(mr->devoice);
mr->devoice = NULL; mr->devoice = NULL;
} }
} }
@ -717,9 +718,8 @@ handle_mode (server * serv, char *word[], char *word_eol[],
if (numeric_324 && !using_front_tab) if (numeric_324 && !using_front_tab)
{ {
if (sess->current_modes) g_free (sess->current_modes);
free (sess->current_modes); sess->current_modes = g_strdup (word_eol[offset+1]);
sess->current_modes = strdup (word_eol[offset+1]);
} }
sign = *modes; sign = *modes;
@ -799,30 +799,29 @@ inbound_005 (server * serv, char *word[], const message_tags_data *tags_data)
serv->modes_per_line = atoi (word[w] + 6); serv->modes_per_line = atoi (word[w] + 6);
} else if (strncmp (word[w], "CHANTYPES=", 10) == 0) } else if (strncmp (word[w], "CHANTYPES=", 10) == 0)
{ {
free (serv->chantypes); g_free (serv->chantypes);
serv->chantypes = strdup (word[w] + 10); serv->chantypes = g_strdup (word[w] + 10);
} else if (strncmp (word[w], "CHANMODES=", 10) == 0) } else if (strncmp (word[w], "CHANMODES=", 10) == 0)
{ {
free (serv->chanmodes); g_free (serv->chanmodes);
serv->chanmodes = strdup (word[w] + 10); serv->chanmodes = g_strdup (word[w] + 10);
} else if (strncmp (word[w], "PREFIX=", 7) == 0) } else if (strncmp (word[w], "PREFIX=", 7) == 0)
{ {
pre = strchr (word[w] + 7, ')'); pre = strchr (word[w] + 7, ')');
if (pre) if (pre)
{ {
pre[0] = 0; /* NULL out the ')' */ pre[0] = 0; /* NULL out the ')' */
free (serv->nick_prefixes); g_free (serv->nick_prefixes);
free (serv->nick_modes); g_free (serv->nick_modes);
serv->nick_prefixes = strdup (pre + 1); serv->nick_prefixes = g_strdup (pre + 1);
serv->nick_modes = strdup (word[w] + 8); serv->nick_modes = g_strdup (word[w] + 8);
} else } else
{ {
/* bad! some ircds don't give us the modes. */ /* bad! some ircds don't give us the modes. */
/* in this case, we use it only to strip /NAMES */ /* in this case, we use it only to strip /NAMES */
serv->bad_prefix = TRUE; serv->bad_prefix = TRUE;
if (serv->bad_nick_prefixes) g_free (serv->bad_nick_prefixes);
free (serv->bad_nick_prefixes); serv->bad_nick_prefixes = g_strdup (word[w] + 7);
serv->bad_nick_prefixes = strdup (word[w] + 7);
} }
} else if (strncmp (word[w], "WATCH=", 6) == 0) } else if (strncmp (word[w], "WATCH=", 6) == 0)
{ {
@ -832,10 +831,6 @@ inbound_005 (server * serv, char *word[], const message_tags_data *tags_data)
serv->supports_monitor = TRUE; serv->supports_monitor = TRUE;
} else if (strncmp (word[w], "NETWORK=", 8) == 0) } else if (strncmp (word[w], "NETWORK=", 8) == 0)
{ {
/* if (serv->networkname)
free (serv->networkname);
serv->networkname = strdup (word[w] + 8);*/
if (serv->server_session->type == SESS_SERVER) if (serv->server_session->type == SESS_SERVER)
{ {
safe_strcpy (serv->server_session->channel, word[w] + 8, CHANLEN); safe_strcpy (serv->server_session->channel, word[w] + 8, CHANLEN);

View File

@ -69,18 +69,13 @@ net_store_destroy (netstore * ns)
if (ns->ip6_hostent) if (ns->ip6_hostent)
freeaddrinfo (ns->ip6_hostent); freeaddrinfo (ns->ip6_hostent);
#endif #endif
free (ns); g_free (ns);
} }
netstore * netstore *
net_store_new (void) net_store_new (void)
{ {
netstore *ns; return g_new0 (netstore, 1);
ns = malloc (sizeof (netstore));
memset (ns, 0, sizeof (netstore));
return ns;
} }
#ifndef USE_IPV6 #ifndef USE_IPV6
@ -120,8 +115,8 @@ net_resolve (netstore * ns, char *hostname, int port, char **real_host)
ns->addr.sin_port = htons (port); ns->addr.sin_port = htons (port);
ns->addr.sin_family = AF_INET; ns->addr.sin_family = AF_INET;
*real_host = strdup (ns->ip4_hostent->h_name); *real_host = g_strdup (ns->ip4_hostent->h_name);
return strdup (inet_ntoa (ns->addr.sin_addr)); return g_strdup (inet_ntoa (ns->addr.sin_addr));
} }
int int
@ -232,11 +227,11 @@ net_resolve (netstore * ns, char *hostname, int port, char **real_host)
ipstring, sizeof (ipstring), NULL, 0, NI_NUMERICHOST); ipstring, sizeof (ipstring), NULL, 0, NI_NUMERICHOST);
if (ns->ip6_hostent->ai_canonname) if (ns->ip6_hostent->ai_canonname)
*real_host = strdup (ns->ip6_hostent->ai_canonname); *real_host = g_strdup (ns->ip6_hostent->ai_canonname);
else else
*real_host = strdup (hostname); *real_host = g_strdup (hostname);
return strdup (ipstring); return g_strdup (ipstring);
} }
/* the only thing making this interface unclean, this shitty sok4, sok6 business */ /* the only thing making this interface unclean, this shitty sok4, sok6 business */
@ -310,15 +305,15 @@ net_store_fill_any (netstore *ns)
struct sockaddr_in *sin; struct sockaddr_in *sin;
ai = ns->ip6_hostent; ai = ns->ip6_hostent;
if (!ai) { if (ai == NULL)
ai = malloc (sizeof (struct addrinfo)); {
memset (ai, 0, sizeof (struct addrinfo)); ai = g_new0 (struct addrinfo, 1);
ns->ip6_hostent = ai; ns->ip6_hostent = ai;
} }
sin = (struct sockaddr_in *)ai->ai_addr; sin = (struct sockaddr_in *)ai->ai_addr;
if (!sin) { if (sin == NULL)
sin = malloc (sizeof (struct sockaddr_in)); {
memset (sin, 0, sizeof (struct sockaddr_in)); sin = g_new0 (struct sockaddr_in, 1);
ai->ai_addr = (struct sockaddr *)sin; ai->ai_addr = (struct sockaddr *)sin;
} }
ai->ai_family = AF_INET; ai->ai_family = AF_INET;
@ -336,15 +331,15 @@ net_store_fill_v4 (netstore *ns, guint32 addr, int port)
struct sockaddr_in *sin; struct sockaddr_in *sin;
ai = ns->ip6_hostent; ai = ns->ip6_hostent;
if (!ai) { if (ai == NULL)
ai = malloc (sizeof (struct addrinfo)); {
memset (ai, 0, sizeof (struct addrinfo)); ai = g_new0 (struct addrinfo, 1);
ns->ip6_hostent = ai; ns->ip6_hostent = ai;
} }
sin = (struct sockaddr_in *)ai->ai_addr; sin = (struct sockaddr_in *)ai->ai_addr;
if (!sin) { if (sin == NULL)
sin = malloc (sizeof (struct sockaddr_in)); {
memset (sin, 0, sizeof (struct sockaddr_in)); sin = g_new0 (struct sockaddr_in, 1);
ai->ai_addr = (struct sockaddr *)sin; ai->ai_addr = (struct sockaddr *)sin;
} }
ai->ai_family = AF_INET; ai->ai_family = AF_INET;

View File

@ -47,7 +47,7 @@ int notify_tag = 0;
static char * static char *
despacify_dup (char *str) despacify_dup (char *str)
{ {
char *p, *res = malloc (strlen (str) + 1); char *p, *res = g_malloc (strlen (str) + 1);
p = res; p = res;
while (1) while (1)
@ -70,11 +70,11 @@ notify_netcmp (char *str, void *serv)
if (rfc_casecmp (str, net) == 0) if (rfc_casecmp (str, net) == 0)
{ {
free (net); g_free (net);
return 0; /* finish & return FALSE from token_foreach() */ return 0; /* finish & return FALSE from token_foreach() */
} }
free (net); g_free (net);
return 1; /* keep going... */ return 1; /* keep going... */
} }
@ -111,14 +111,10 @@ notify_find_server_entry (struct notify *notify, struct server *serv)
if (!notify_do_network (notify, serv)) if (!notify_do_network (notify, serv))
return NULL; return NULL;
servnot = malloc (sizeof (struct notify_per_server)); servnot = g_new0 (struct notify_per_server, 1);
if (servnot)
{
memset (servnot, 0, sizeof (struct notify_per_server));
servnot->server = serv; servnot->server = serv;
servnot->notify = notify; servnot->notify = notify;
notify->server_list = g_slist_prepend (notify->server_list, servnot); notify->server_list = g_slist_prepend (notify->server_list, servnot);
}
return servnot; return servnot;
} }
@ -247,10 +243,9 @@ notify_announce_online (server * serv, struct notify_per_server *servnot,
/* Let's do whois with idle time (like in /quote WHOIS %s %s) */ /* Let's do whois with idle time (like in /quote WHOIS %s %s) */
char *wii_str = malloc (strlen (nick) * 2 + 2); char *wii_str = g_strdup_printf ("%s %s", nick, nick);
sprintf (wii_str, "%s %s", nick, nick);
serv->p_whois (serv, wii_str); serv->p_whois (serv, wii_str);
free (wii_str); g_free (wii_str);
} }
} }
@ -596,14 +591,13 @@ notify_deluser (char *name)
servnot = (struct notify_per_server *) notify->server_list->data; servnot = (struct notify_per_server *) notify->server_list->data;
notify->server_list = notify->server_list =
g_slist_remove (notify->server_list, servnot); g_slist_remove (notify->server_list, servnot);
free (servnot); g_free (servnot);
} }
notify_list = g_slist_remove (notify_list, notify); notify_list = g_slist_remove (notify_list, notify);
notify_watch_all (notify, FALSE); notify_watch_all (notify, FALSE);
if (notify->networks) g_free (notify->networks);
free (notify->networks); g_free (notify->name);
free (notify->name); g_free (notify);
free (notify);
fe_notify_update (0); fe_notify_update (0);
return 1; return 1;
} }
@ -615,19 +609,11 @@ notify_deluser (char *name)
void void
notify_adduser (char *name, char *networks) notify_adduser (char *name, char *networks)
{ {
struct notify *notify = malloc (sizeof (struct notify)); struct notify *notify = g_new0 (struct notify, 1);
if (notify)
{ notify->name = g_strndup (name, NICKLEN - 1);
memset (notify, 0, sizeof (struct notify));
if (strlen (name) >= NICKLEN) if (networks != NULL)
{
notify->name = malloc (NICKLEN);
safe_strcpy (notify->name, name, NICKLEN);
} else
{
notify->name = strdup (name);
}
if (networks)
notify->networks = despacify_dup (networks); notify->networks = despacify_dup (networks);
notify->server_list = 0; notify->server_list = 0;
notify_list = g_slist_prepend (notify_list, notify); notify_list = g_slist_prepend (notify_list, notify);
@ -635,7 +621,6 @@ notify_adduser (char *name, char *networks)
fe_notify_update (notify->name); fe_notify_update (notify->name);
fe_notify_update (0); fe_notify_update (0);
notify_watch_all (notify, TRUE); notify_watch_all (notify, TRUE);
}
} }
gboolean gboolean
@ -714,7 +699,7 @@ notify_cleanup ()
{ {
notify->server_list = notify->server_list =
g_slist_remove (notify->server_list, servnot); g_slist_remove (notify->server_list, servnot);
free (servnot); g_free (servnot);
nslist = notify->server_list; nslist = notify->server_list;
} else } else
{ {

View File

@ -90,7 +90,7 @@ random_line (char *file_name)
{ {
nofile: nofile:
/* reason is not a file, an actual reason! */ /* reason is not a file, an actual reason! */
return strdup (file_name); return g_strdup (file_name);
} }
/* count number of lines in file */ /* count number of lines in file */
@ -111,7 +111,7 @@ random_line (char *file_name)
} }
while (lines > ran); while (lines > ran);
fclose (fh); fclose (fh);
return strdup (buf); return g_strdup (buf);
} }
void void
@ -121,7 +121,7 @@ server_sendpart (server * serv, char *channel, char *reason)
{ {
reason = random_line (prefs.hex_irc_part_reason); reason = random_line (prefs.hex_irc_part_reason);
serv->p_part (serv, channel, reason); serv->p_part (serv, channel, reason);
free (reason); g_free (reason);
} else } else
{ {
/* reason set by /quit, /close argument */ /* reason set by /quit, /close argument */
@ -136,12 +136,12 @@ server_sendquit (session * sess)
if (!sess->quitreason) if (!sess->quitreason)
{ {
colrea = strdup (prefs.hex_irc_quit_reason); colrea = g_strdup (prefs.hex_irc_quit_reason);
check_special_chars (colrea, FALSE); check_special_chars (colrea, FALSE);
rea = random_line (colrea); rea = random_line (colrea);
free (colrea); g_free (colrea);
sess->server->p_quit (sess->server, rea); sess->server->p_quit (sess->server, rea);
free (rea); g_free (rea);
} else } else
{ {
/* reason set by /quit, /close argument */ /* reason set by /quit, /close argument */
@ -269,7 +269,7 @@ cmd_addserver (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!network) if (!network)
{ {
network = servlist_net_add (word[2], "", TRUE); network = servlist_net_add (word[2], "", TRUE);
network->encoding = strdup (IRC_DEFAULT_CHARSET); network->encoding = g_strdup (IRC_DEFAULT_CHARSET);
} }
/* if we had the network already, check if the given server already exists */ /* if we had the network already, check if the given server already exists */
else if (servlist_server_find (network, word_eol[3], NULL)) else if (servlist_server_find (network, word_eol[3], NULL))
@ -379,11 +379,10 @@ cmd_away (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (sess->server->last_away_reason != reason) if (sess->server->last_away_reason != reason)
{ {
if (sess->server->last_away_reason) g_free (sess->server->last_away_reason);
free (sess->server->last_away_reason);
if (reason == word_eol[2]) if (reason == word_eol[2])
sess->server->last_away_reason = strdup (reason); sess->server->last_away_reason = g_strdup (reason);
else else
sess->server->last_away_reason = reason; sess->server->last_away_reason = reason;
} }
@ -406,8 +405,7 @@ cmd_back (struct session *sess, char *tbuf, char *word[], char *word_eol[])
PrintText (sess, _("Already marked back.\n")); PrintText (sess, _("Already marked back.\n"));
} }
if (sess->server->last_away_reason) g_free (sess->server->last_away_reason);
free (sess->server->last_away_reason);
sess->server->last_away_reason = NULL; sess->server->last_away_reason = NULL;
return TRUE; return TRUE;
@ -1002,14 +1000,14 @@ mdehop_cb (struct User *user, multidata *data)
static int static int
cmd_mdehop (struct session *sess, char *tbuf, char *word[], char *word_eol[]) cmd_mdehop (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{ {
char **nicks = malloc (sizeof (char *) * sess->hops); char **nicks = g_new0 (char *, sess->hops);
multidata data; multidata data;
data.nicks = nicks; data.nicks = nicks;
data.i = 0; data.i = 0;
tree_foreach (sess->usertree, (tree_traverse_func *)mdehop_cb, &data); tree_foreach (sess->usertree, (tree_traverse_func *)mdehop_cb, &data);
send_channel_modes (sess, tbuf, nicks, 0, data.i, '-', 'h', 0); send_channel_modes (sess, tbuf, nicks, 0, data.i, '-', 'h', 0);
free (nicks); g_free (nicks);
return TRUE; return TRUE;
} }
@ -1028,14 +1026,14 @@ mdeop_cb (struct User *user, multidata *data)
static int static int
cmd_mdeop (struct session *sess, char *tbuf, char *word[], char *word_eol[]) cmd_mdeop (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{ {
char **nicks = malloc (sizeof (char *) * sess->ops); char **nicks = g_new0(char *, sess->ops);
multidata data; multidata data;
data.nicks = nicks; data.nicks = nicks;
data.i = 0; data.i = 0;
tree_foreach (sess->usertree, (tree_traverse_func *)mdeop_cb, &data); tree_foreach (sess->usertree, (tree_traverse_func *)mdeop_cb, &data);
send_channel_modes (sess, tbuf, nicks, 0, data.i, '-', 'o', 0); send_channel_modes (sess, tbuf, nicks, 0, data.i, '-', 'o', 0);
free (nicks); g_free (nicks);
return TRUE; return TRUE;
} }
@ -1045,18 +1043,13 @@ GSList *menu_list = NULL;
static void static void
menu_free (menu_entry *me) menu_free (menu_entry *me)
{ {
free (me->path); g_free (me->path);
if (me->label) g_free (me->label);
free (me->label); g_free (me->cmd);
if (me->cmd) g_free (me->ucmd);
free (me->cmd); g_free (me->group);
if (me->ucmd) g_free (me->icon);
free (me->ucmd); g_free (me);
if (me->group)
free (me->group);
if (me->icon)
free (me->icon);
free (me);
} }
/* strings equal? but ignore underscores */ /* strings equal? but ignore underscores */
@ -1195,7 +1188,7 @@ menu_add (char *path, char *label, char *cmd, char *ucmd, int pos, int state, in
return; return;
} }
me = malloc (sizeof (menu_entry)); me = g_new (menu_entry, 1);
me->pos = pos; me->pos = pos;
me->modifier = mod; me->modifier = mod;
me->is_main = menu_is_mainmenu_root (path, &me->root_offset); me->is_main = menu_is_mainmenu_root (path, &me->root_offset);
@ -1203,31 +1196,26 @@ menu_add (char *path, char *label, char *cmd, char *ucmd, int pos, int state, in
me->markup = markup; me->markup = markup;
me->enable = enable; me->enable = enable;
me->key = key; me->key = key;
me->path = strdup (path); me->path = g_strdup (path);
me->label = NULL; me->label = NULL;
me->cmd = NULL; me->cmd = NULL;
me->ucmd = NULL; me->ucmd = NULL;
me->group = NULL; me->group = NULL;
me->icon = NULL; me->icon = NULL;
if (label) me->label = g_strdup (label);
me->label = strdup (label); me->cmd = g_strdup (cmd);
if (cmd) me->ucmd = g_strdup (ucmd);
me->cmd = strdup (cmd); me->group = g_strdup (group);
if (ucmd) me->icon = g_strdup (icon);
me->ucmd = strdup (ucmd);
if (group)
me->group = strdup (group);
if (icon)
me->icon = strdup (icon);
menu_list = g_slist_append (menu_list, me); menu_list = g_slist_append (menu_list, me);
label = fe_menu_add (me); label = fe_menu_add (me);
if (label) if (label)
{ {
/* FE has given us a stripped label */ /* FE has given us a stripped label */
free (me->label); g_free (me->label);
me->label = strdup (label); me->label = g_strdup (label);
g_free (label); /* this is from pango */ g_free (label); /* this is from pango */
} }
} }
@ -1456,7 +1444,7 @@ exec_check_process (struct session *sess)
{ {
close (sess->running_exec->myfd); close (sess->running_exec->myfd);
fe_input_remove (sess->running_exec->iotag); fe_input_remove (sess->running_exec->iotag);
free (sess->running_exec); g_free (sess->running_exec);
sess->running_exec = NULL; sess->running_exec = NULL;
} }
} }
@ -1533,11 +1521,10 @@ cmd_execw (struct session *sess, char *tbuf, char *word[], char *word_eol[])
return FALSE; return FALSE;
} }
len = strlen(word_eol[2]); len = strlen(word_eol[2]);
temp = malloc(len + 2); temp = g_strconcat (word_eol[2], "\n", NULL);
sprintf(temp, "%s\n", word_eol[2]);
PrintText(sess, temp); PrintText(sess, temp);
write(sess->running_exec->myfd, temp, len + 1); write(sess->running_exec->myfd, temp, len + 1);
free(temp); g_free(temp);
return TRUE; return TRUE;
} }
@ -1561,7 +1548,7 @@ exec_handle_colors (char *buf, int len)
if (strchr (buf, 27) == 0) if (strchr (buf, 27) == 0)
return; return;
nbuf = malloc (len + 1); nbuf = g_malloc (len + 1);
while (i < len) while (i < len)
{ {
@ -1655,7 +1642,7 @@ norm: nbuf[j] = buf[i];
nbuf[j] = 0; nbuf[j] = 0;
memcpy (buf, nbuf, j + 1); memcpy (buf, nbuf, j + 1);
free (nbuf); g_free (nbuf);
} }
#ifndef HAVE_MEMRCHR #ifndef HAVE_MEMRCHR
@ -1681,14 +1668,14 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
len = s->buffill; len = s->buffill;
if (len) { if (len) {
/* append new data to buffered incomplete line */ /* append new data to buffered incomplete line */
buf = malloc(len + 2050); buf = g_malloc (len + 2050);
memcpy(buf, s->linebuf, len); memcpy(buf, s->linebuf, len);
readpos = buf + len; readpos = buf + len;
free(s->linebuf); g_free (s->linebuf);
s->linebuf = NULL; s->linebuf = NULL;
} }
else else
readpos = buf = malloc(2050); readpos = buf = g_malloc (2050);
rd = read (sok, readpos, 2048); rd = read (sok, readpos, 2048);
if (rd < 1) if (rd < 1)
@ -1709,12 +1696,12 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
else else
PrintText (s->sess, buf); PrintText (s->sess, buf);
} }
free(buf); g_free(buf);
waitpid (s->childpid, NULL, 0); waitpid (s->childpid, NULL, 0);
s->sess->running_exec = NULL; s->sess->running_exec = NULL;
fe_input_remove (s->iotag); fe_input_remove (s->iotag);
close (sok); close (sok);
free (s); g_free (s);
return TRUE; return TRUE;
} }
len += rd; len += rd;
@ -1727,7 +1714,7 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
rest = buf; rest = buf;
if (*rest) { if (*rest) {
s->buffill = len - (rest - buf); /* = strlen(rest) */ s->buffill = len - (rest - buf); /* = strlen(rest) */
s->linebuf = malloc(s->buffill + 1); s->linebuf = g_malloc (s->buffill + 1);
memcpy(s->linebuf, rest, s->buffill); memcpy(s->linebuf, rest, s->buffill);
*rest = '\0'; *rest = '\0';
len -= s->buffill; /* possibly 0 */ len -= s->buffill; /* possibly 0 */
@ -1743,7 +1730,7 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
PrintText (s->sess, buf); PrintText (s->sess, buf);
} }
free(buf); g_free (buf);
return TRUE; return TRUE;
} }
@ -1805,8 +1792,7 @@ cmd_exec (struct session *sess, char *tbuf, char *word[], char *word_eol[])
return FALSE; return FALSE;
} }
#endif #endif
s = (struct nbexec *) malloc (sizeof (struct nbexec)); s = g_new0 (struct nbexec, 1);
memset(s, 0, sizeof(*s));
s->myfd = fds[0]; s->myfd = fds[0];
s->tochannel = tochannel; s->tochannel = tochannel;
s->sess = sess; s->sess = sess;
@ -1853,8 +1839,9 @@ cmd_exec (struct session *sess, char *tbuf, char *word[], char *word_eol[])
PrintText (sess, "Error in fork(2)\n"); PrintText (sess, "Error in fork(2)\n");
close(fds[0]); close(fds[0]);
close(fds[1]); close(fds[1]);
free (s); g_free (s);
} else }
else
{ {
/* Parent path */ /* Parent path */
close(fds[1]); close(fds[1]);
@ -1946,8 +1933,8 @@ get_bool_cb (int val, getvalinfo *info)
if (is_session (info->sess)) if (is_session (info->sess))
handle_command (info->sess, buf, FALSE); handle_command (info->sess, buf, FALSE);
free (info->cmd); g_free (info->cmd);
free (info); g_free (info);
} }
static int static int
@ -1958,8 +1945,8 @@ cmd_getbool (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!word[4][0]) if (!word[4][0])
return FALSE; return FALSE;
info = malloc (sizeof (*info)); info = g_new (getvalinfo, 1);
info->cmd = strdup (word[2]); info->cmd = g_strdup (word[2]);
info->sess = sess; info->sess = sess;
fe_get_bool (word[3], word_eol[4], get_bool_cb, info); fe_get_bool (word[3], word_eol[4], get_bool_cb, info);
@ -1979,8 +1966,8 @@ get_int_cb (int cancel, int val, getvalinfo *info)
handle_command (info->sess, buf, FALSE); handle_command (info->sess, buf, FALSE);
} }
free (info->cmd); g_free (info->cmd);
free (info); g_free (info);
} }
static int static int
@ -1991,8 +1978,8 @@ cmd_getint (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!word[4][0]) if (!word[4][0])
return FALSE; return FALSE;
info = malloc (sizeof (*info)); info = g_new (getvalinfo, 1);
info->cmd = strdup (word[3]); info->cmd = g_strdup (word[3]);
info->sess = sess; info->sess = sess;
fe_get_int (word[4], atoi (word[2]), get_int_cb, info); fe_get_int (word[4], atoi (word[2]), get_int_cb, info);
@ -2015,7 +2002,7 @@ get_file_cb (char *cmd, char *file)
else else
{ {
handle_command (current_sess, cmd, FALSE); handle_command (current_sess, cmd, FALSE);
free (cmd); g_free (cmd);
} }
} }
@ -2046,7 +2033,7 @@ cmd_getfile (struct session *sess, char *tbuf, char *word[], char *word_eol[])
idx++; idx++;
} }
fe_get_file (word[idx+1], word[idx+2], (void *)get_file_cb, strdup (word[idx]), flags); fe_get_file (word[idx+1], word[idx+2], (void *)get_file_cb, g_strdup (word[idx]), flags);
return TRUE; return TRUE;
} }
@ -2063,8 +2050,8 @@ get_str_cb (int cancel, char *val, getvalinfo *info)
handle_command (info->sess, buf, FALSE); handle_command (info->sess, buf, FALSE);
} }
free (info->cmd); g_free (info->cmd);
free (info); g_free (info);
} }
static int static int
@ -2075,8 +2062,8 @@ cmd_getstr (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!word[4][0]) if (!word[4][0])
return FALSE; return FALSE;
info = malloc (sizeof (*info)); info = g_new (getvalinfo, 1);
info->cmd = strdup (word[3]); info->cmd = g_strdup (word[3]);
info->sess = sess; info->sess = sess;
fe_get_str (word[4], word[2], get_str_cb, info); fe_get_str (word[4], word[2], get_str_cb, info);
@ -2202,7 +2189,7 @@ cmd_help (struct session *sess, char *tbuf, char *word[], char *word_eol[])
} else } else
{ {
struct popup *pop; struct popup *pop;
char *buf = malloc (4096); char *buf = g_malloc (4096);
help_list hl; help_list hl;
hl.longfmt = longfmt; hl.longfmt = longfmt;
@ -2247,7 +2234,7 @@ cmd_help (struct session *sess, char *tbuf, char *word[], char *word_eol[])
plugin_command_foreach (sess, &hl, (void *)show_help_line); plugin_command_foreach (sess, &hl, (void *)show_help_line);
strcat (buf, "\n"); strcat (buf, "\n");
PrintText (sess, buf); PrintText (sess, buf);
free (buf); g_free (buf);
PrintTextf (sess, "\n%s\n\n", _("Type /HELP <command> for more information, or /HELP -l")); PrintTextf (sess, "\n%s\n\n", _("Type /HELP <command> for more information, or /HELP -l"));
} }
@ -2723,7 +2710,7 @@ mop_cb (struct User *user, multidata *data)
static int static int
cmd_mop (struct session *sess, char *tbuf, char *word[], char *word_eol[]) cmd_mop (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{ {
char **nicks = malloc (sizeof (char *) * (sess->total - sess->ops)); char **nicks = g_new0 (char *, sess->total - sess->ops);
multidata data; multidata data;
data.nicks = nicks; data.nicks = nicks;
@ -2731,7 +2718,7 @@ cmd_mop (struct session *sess, char *tbuf, char *word[], char *word_eol[])
tree_foreach (sess->usertree, (tree_traverse_func *)mop_cb, &data); tree_foreach (sess->usertree, (tree_traverse_func *)mop_cb, &data);
send_channel_modes (sess, tbuf, nicks, 0, data.i, '+', 'o', 0); send_channel_modes (sess, tbuf, nicks, 0, data.i, '+', 'o', 0);
free (nicks); g_free (nicks);
return TRUE; return TRUE;
} }
@ -4313,10 +4300,8 @@ check_special_chars (char *cmd, int do_ascii) /* check for %X */
if (!len) if (!len)
return; return;
buf = malloc (len + 1); buf = g_malloc (len + 1);
if (buf)
{
while (cmd[j]) while (cmd[j])
{ {
switch (cmd[j]) switch (cmd[j])
@ -4386,8 +4371,7 @@ check_special_chars (char *cmd, int do_ascii) /* check for %X */
buf[i] = 0; buf[i] = 0;
if (occur) if (occur)
strcpy (cmd, buf); strcpy (cmd, buf);
free (buf); g_free (buf);
}
} }
typedef struct typedef struct
@ -4487,12 +4471,10 @@ handle_say (session *sess, char *text, int check_spch)
struct DCC *dcc; struct DCC *dcc;
char *word[PDIWORDS+1]; char *word[PDIWORDS+1];
char *word_eol[PDIWORDS+1]; char *word_eol[PDIWORDS+1];
char pdibuf_static[1024]; char *pdibuf;
char newcmd_static[1024]; char *newcmd;
char *pdibuf = pdibuf_static;
char *newcmd = newcmd_static;
int len; int len;
int newcmdlen = sizeof newcmd_static; int newcmdlen;
message_tags_data no_tags = MESSAGE_TAGS_DATA_INIT; message_tags_data no_tags = MESSAGE_TAGS_DATA_INIT;
if (strcmp (sess->channel, "(lastlog)") == 0) if (strcmp (sess->channel, "(lastlog)") == 0)
@ -4502,11 +4484,9 @@ handle_say (session *sess, char *text, int check_spch)
} }
len = strlen (text); len = strlen (text);
if (len >= sizeof pdibuf_static) pdibuf = g_malloc (len + 1);
pdibuf = malloc (len + 1); newcmdlen = MAX(len + NICKLEN + 1, TBUFSIZE);
newcmd = g_malloc (newcmdlen);
if (len + NICKLEN >= newcmdlen)
newcmd = malloc (newcmdlen = len + NICKLEN + 1);
if (check_spch && prefs.hex_input_perc_color) if (check_spch && prefs.hex_input_perc_color)
check_special_chars (text, prefs.hex_input_perc_ascii); check_special_chars (text, prefs.hex_input_perc_ascii);
@ -4579,11 +4559,9 @@ handle_say (session *sess, char *text, int check_spch)
} }
xit: xit:
if (pdibuf != pdibuf_static) g_free (pdibuf);
free (pdibuf);
if (newcmd != newcmd_static) g_free (newcmd);
free (newcmd);
} }
char * char *
@ -4677,8 +4655,6 @@ handle_command (session *sess, char *cmd, int check_spch)
char *word_eol[PDIWORDS+1]; char *word_eol[PDIWORDS+1];
static int command_level = 0; static int command_level = 0;
struct commands *int_cmd; struct commands *int_cmd;
char pdibuf_static[1024];
char tbuf_static[TBUFSIZE];
char *pdibuf; char *pdibuf;
char *tbuf; char *tbuf;
int len; int len;
@ -4693,23 +4669,8 @@ handle_command (session *sess, char *cmd, int check_spch)
/* anything below MUST DEC command_level before returning */ /* anything below MUST DEC command_level before returning */
len = strlen (cmd); len = strlen (cmd);
if (len >= sizeof (pdibuf_static)) pdibuf = g_malloc (len + 1);
{ tbuf = g_malloc (MAX(TBUFSIZE, (len * 2) + 1));
pdibuf = malloc (len + 1);
}
else
{
pdibuf = pdibuf_static;
}
if ((len * 2) >= sizeof (tbuf_static))
{
tbuf = malloc ((len * 2) + 1);
}
else
{
tbuf = tbuf_static;
}
/* split the text into words and word_eol */ /* split the text into words and word_eol */
process_data_init (pdibuf, cmd, word, word_eol, TRUE, TRUE); process_data_init (pdibuf, cmd, word, word_eol, TRUE, TRUE);
@ -4802,15 +4763,8 @@ handle_command (session *sess, char *cmd, int check_spch)
xit: xit:
command_level--; command_level--;
if (pdibuf != pdibuf_static) g_free (pdibuf);
{ g_free (tbuf);
free (pdibuf);
}
if (tbuf != tbuf_static)
{
free (tbuf);
}
return ret; return ret;
} }

View File

@ -53,9 +53,9 @@ static void
timer_del (timer *tim) timer_del (timer *tim)
{ {
timer_list = g_slist_remove (timer_list, tim); timer_list = g_slist_remove (timer_list, tim);
free (tim->command); g_free (tim->command);
hexchat_unhook (ph, tim->hook); hexchat_unhook (ph, tim->hook);
free (tim); g_free (tim);
} }
static void static void
@ -119,11 +119,11 @@ timer_add (int ref, int timeout, int repeat, char *command)
} }
} }
tim = malloc (sizeof (timer)); tim = g_new (timer, 1);
tim->ref = ref; tim->ref = ref;
tim->repeat = repeat; tim->repeat = repeat;
tim->timeout = timeout; tim->timeout = timeout;
tim->command = strdup (command); tim->command = g_strdup (command);
tim->context = hexchat_get_context (ph); tim->context = hexchat_get_context (ph);
tim->forever = FALSE; tim->forever = FALSE;

View File

@ -161,16 +161,12 @@ plugin_free (hexchat_plugin *pl, int do_deinit, int allow_refuse)
xit: xit:
if (pl->free_strings) if (pl->free_strings)
{ {
if (pl->name) g_free (pl->name);
free (pl->name); g_free (pl->desc);
if (pl->desc) g_free (pl->version);
free (pl->desc);
if (pl->version)
free (pl->version);
} }
if (pl->filename) g_free ((char *)pl->filename);
free ((char *)pl->filename); g_free (pl);
free (pl);
plugin_list = g_slist_remove (plugin_list, pl); plugin_list = g_slist_remove (plugin_list, pl);
@ -188,7 +184,7 @@ plugin_list_add (hexchat_context *ctx, char *filename, const char *name,
{ {
hexchat_plugin *pl; hexchat_plugin *pl;
pl = malloc (sizeof (hexchat_plugin)); pl = g_new (hexchat_plugin, 1);
pl->handle = handle; pl->handle = handle;
pl->filename = filename; pl->filename = filename;
pl->context = ctx; pl->context = ctx;
@ -239,9 +235,7 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func,
hexchat_plugin *pl; hexchat_plugin *pl;
char *file; char *file;
file = NULL; file = g_strdup (filename);
if (filename)
file = strdup (filename);
pl = plugin_list_add (sess, file, file, NULL, NULL, handle, deinit_func, pl = plugin_list_add (sess, file, file, NULL, NULL, handle, deinit_func,
fake, FALSE); fake, FALSE);
@ -596,7 +590,7 @@ xit:
if (!hook || hook->type == HOOK_DELETED) if (!hook || hook->type == HOOK_DELETED)
{ {
hook_list = g_slist_remove (hook_list, hook); hook_list = g_slist_remove (hook_list, hook);
free (hook); g_free (hook);
} }
list = next; list = next;
} }
@ -615,13 +609,7 @@ plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[])
hexchat_event_attrs * hexchat_event_attrs *
hexchat_event_attrs_create (hexchat_plugin *ph) hexchat_event_attrs_create (hexchat_plugin *ph)
{ {
hexchat_event_attrs *attrs; return g_new0 (hexchat_event_attrs, 1);
attrs = g_malloc (sizeof (*attrs));
attrs->server_time_utc = (time_t) 0;
return attrs;
} }
void void
@ -796,15 +784,11 @@ plugin_add_hook (hexchat_plugin *pl, int type, int pri, const char *name,
{ {
hexchat_hook *hook; hexchat_hook *hook;
hook = malloc (sizeof (hexchat_hook)); hook = g_new0 (hexchat_hook, 1);
memset (hook, 0, sizeof (hexchat_hook));
hook->type = type; hook->type = type;
hook->pri = pri; hook->pri = pri;
if (name) hook->name = g_strdup (name);
hook->name = strdup (name); hook->help_text = g_strdup (help_text);
if (help_text)
hook->help_text = strdup (help_text);
hook->callback = callb; hook->callback = callb;
hook->pl = pl; hook->pl = pl;
hook->userdata = userdata; hook->userdata = userdata;
@ -892,10 +876,8 @@ hexchat_unhook (hexchat_plugin *ph, hexchat_hook *hook)
hook->type = HOOK_DELETED; /* expunge later */ hook->type = HOOK_DELETED; /* expunge later */
if (hook->name) g_free (hook->name); /* NULL for timers & fds */
free (hook->name); /* NULL for timers & fds */ g_free (hook->help_text); /* NULL for non-commands */
if (hook->help_text)
free (hook->help_text); /* NULL for non-commands */
return hook->userdata; return hook->userdata;
} }
@ -1263,8 +1245,7 @@ hexchat_list_get (hexchat_plugin *ph, const char *name)
{ {
hexchat_list *list; hexchat_list *list;
list = malloc (sizeof (hexchat_list)); list = g_new0 (hexchat_list, 1);
list->pos = NULL;
switch (str_hash (name)) switch (str_hash (name))
{ {
@ -1299,7 +1280,7 @@ hexchat_list_get (hexchat_plugin *ph, const char *name)
} /* fall through */ } /* fall through */
default: default:
free (list); g_free (list);
return NULL; return NULL;
} }
@ -1311,7 +1292,7 @@ hexchat_list_free (hexchat_plugin *ph, hexchat_list *xlist)
{ {
if (xlist->type == LIST_USERS) if (xlist->type == LIST_USERS)
g_slist_free (xlist->head); g_slist_free (xlist->head);
free (xlist); g_free (xlist);
} }
int int
@ -1651,8 +1632,8 @@ hexchat_plugingui_add (hexchat_plugin *ph, const char *filename,
const char *version, char *reserved) const char *version, char *reserved)
{ {
#ifdef USE_PLUGIN #ifdef USE_PLUGIN
ph = plugin_list_add (NULL, strdup (filename), strdup (name), strdup (desc), ph = plugin_list_add (NULL, g_strdup (filename), g_strdup (name), g_strdup (desc),
strdup (version), NULL, NULL, TRUE, TRUE); g_strdup (version), NULL, NULL, TRUE, TRUE);
fe_pluginlist_update (); fe_pluginlist_update ();
#endif #endif
@ -1917,7 +1898,6 @@ hexchat_pluginpref_get_str_real (hexchat_plugin *pl, const char *var, char *dest
g_free (confname); g_free (confname);
return 0; return 0;
} }
g_free (confname); g_free (confname);
if (!cfg_get_str (cfg, var, buf, sizeof(buf))) if (!cfg_get_str (cfg, var, buf, sizeof(buf)))

View File

@ -1481,13 +1481,10 @@ irc_inline (server *serv, char *buf, int len)
char *type, *text; char *type, *text;
char *word[PDIWORDS+1]; char *word[PDIWORDS+1];
char *word_eol[PDIWORDS+1]; char *word_eol[PDIWORDS+1];
char pdibuf_static[522]; /* 1 line can potentially be 512*6 in utf8 */ char *pdibuf;
char *pdibuf = pdibuf_static;
message_tags_data tags_data = MESSAGE_TAGS_DATA_INIT; message_tags_data tags_data = MESSAGE_TAGS_DATA_INIT;
/* need more than 522? fall back to malloc */ pdibuf = g_malloc (len + 1);
if (len >= sizeof (pdibuf_static))
pdibuf = malloc (len + 1);
sess = serv->front_session; sess = serv->front_session;
@ -1566,8 +1563,7 @@ irc_inline (server *serv, char *buf, int len)
} }
xit: xit:
if (pdibuf != pdibuf_static) g_free (pdibuf);
free (pdibuf);
} }
void void

View File

@ -212,7 +212,7 @@ tcp_send_queue (server *serv)
buf--; buf--;
serv->outbound_queue = g_slist_remove (serv->outbound_queue, buf); serv->outbound_queue = g_slist_remove (serv->outbound_queue, buf);
free (buf); g_free (buf);
list = serv->outbound_queue; list = serv->outbound_queue;
} else } else
{ {
@ -234,7 +234,7 @@ tcp_send_len (server *serv, char *buf, int len)
if (!prefs.hex_net_throttle) if (!prefs.hex_net_throttle)
return server_send_real (serv, buf, len); return server_send_real (serv, buf, len);
dbuf = malloc (len + 2); /* first byte is the priority */ dbuf = g_malloc (len + 2); /* first byte is the priority */
dbuf[0] = 2; /* pri 2 for most things */ dbuf[0] = 2; /* pri 2 for most things */
memcpy (dbuf + 1, buf, len); memcpy (dbuf + 1, buf, len);
dbuf[len + 1] = 0; dbuf[len + 1] = 0;
@ -527,7 +527,7 @@ server_close_pipe (int *pipefd) /* see comments below */
{ {
close (pipefd[0]); /* close WRITE end first to cause an EOF on READ */ close (pipefd[0]); /* close WRITE end first to cause an EOF on READ */
close (pipefd[1]); /* in giowin32, and end that thread. */ close (pipefd[1]); /* in giowin32, and end that thread. */
free (pipefd); g_free (pipefd);
return FALSE; return FALSE;
} }
@ -560,7 +560,7 @@ server_stopconnecting (server * serv)
{ {
/* if we close the pipe now, giowin32 will crash. */ /* if we close the pipe now, giowin32 will crash. */
int *pipefd = malloc (sizeof (int) * 2); int *pipefd = g_new (int, 2);
pipefd[0] = serv->childwrite; pipefd[0] = serv->childwrite;
pipefd[1] = serv->childread; pipefd[1] = serv->childread;
g_idle_add ((GSourceFunc)server_close_pipe, pipefd); g_idle_add ((GSourceFunc)server_close_pipe, pipefd);
@ -1282,7 +1282,7 @@ traverse_socks5 (int print_fd, int sok, char *serverAddr, int port)
addrlen = strlen (serverAddr); addrlen = strlen (serverAddr);
packetlen = 4 + 1 + addrlen + 2; packetlen = 4 + 1 + addrlen + 2;
sc2 = malloc (packetlen); sc2 = g_malloc (packetlen);
sc2[0] = 5; /* version */ sc2[0] = 5; /* version */
sc2[1] = 1; /* command */ sc2[1] = 1; /* command */
sc2[2] = 0; /* reserved */ sc2[2] = 0; /* reserved */
@ -1291,7 +1291,7 @@ traverse_socks5 (int print_fd, int sok, char *serverAddr, int port)
memcpy (sc2 + 5, serverAddr, addrlen); memcpy (sc2 + 5, serverAddr, addrlen);
*((unsigned short *) (sc2 + 5 + addrlen)) = htons (port); *((unsigned short *) (sc2 + 5 + addrlen)) = htons (port);
send (sok, sc2, packetlen, 0); send (sok, sc2, packetlen, 0);
free (sc2); g_free (sc2);
/* consume all of the reply */ /* consume all of the reply */
if (recv (sok, buf, 4, 0) != 4) if (recv (sok, buf, 4, 0) != 4)
@ -1542,7 +1542,7 @@ server_child (server * serv)
if (proxy_type) { if (proxy_type) {
char *c; char *c;
c = strchr (proxy, ':') + 3; c = strchr (proxy, ':') + 3;
proxy_host = strdup (c); proxy_host = g_strdup (c);
c = strchr (proxy_host, ':'); c = strchr (proxy_host, ':');
*c = '\0'; *c = '\0';
proxy_port = atoi (c + 1); proxy_port = atoi (c + 1);
@ -1557,7 +1557,7 @@ server_child (server * serv)
prefs.hex_net_proxy_use != 2) /* proxy is NOT dcc-only */ prefs.hex_net_proxy_use != 2) /* proxy is NOT dcc-only */
{ {
proxy_type = prefs.hex_net_proxy_type; proxy_type = prefs.hex_net_proxy_type;
proxy_host = strdup (prefs.hex_net_proxy_host); proxy_host = g_strdup (prefs.hex_net_proxy_host);
proxy_port = prefs.hex_net_proxy_port; proxy_port = prefs.hex_net_proxy_port;
} }
} }
@ -1570,7 +1570,7 @@ server_child (server * serv)
snprintf (buf, sizeof (buf), "9\n%s\n", proxy_host); snprintf (buf, sizeof (buf), "9\n%s\n", proxy_host);
write (serv->childwrite, buf, strlen (buf)); write (serv->childwrite, buf, strlen (buf));
ip = net_resolve (ns_server, proxy_host, proxy_port, &real_hostname); ip = net_resolve (ns_server, proxy_host, proxy_port, &real_hostname);
free (proxy_host); g_free (proxy_host);
if (!ip) if (!ip)
{ {
write (serv->childwrite, "1\n", 2); write (serv->childwrite, "1\n", 2);
@ -1589,7 +1589,7 @@ server_child (server * serv)
goto xit; goto xit;
} }
} else /* otherwise we can just use the hostname */ } else /* otherwise we can just use the hostname */
proxy_ip = strdup (hostname); proxy_ip = g_strdup (hostname);
} else } else
{ {
ip = net_resolve (ns_server, hostname, port, &real_hostname); ip = net_resolve (ns_server, hostname, port, &real_hostname);
@ -1657,12 +1657,9 @@ xit:
/* no need to free ip/real_hostname, this process is exiting */ /* no need to free ip/real_hostname, this process is exiting */
#ifdef WIN32 #ifdef WIN32
/* under win32 we use a thread -> shared memory, must free! */ /* under win32 we use a thread -> shared memory, must free! */
if (proxy_ip) g_free (proxy_ip);
free (proxy_ip); g_free (ip);
if (ip) g_free (real_hostname);
free (ip);
if (real_hostname)
free (real_hostname);
#endif #endif
return 0; return 0;
@ -1827,7 +1824,7 @@ server_set_encoding (server *serv, char *new_encoding)
if (serv->encoding) if (serv->encoding)
{ {
free (serv->encoding); g_free (serv->encoding);
/* can be left as NULL to indicate system encoding */ /* can be left as NULL to indicate system encoding */
serv->encoding = NULL; serv->encoding = NULL;
serv->using_cp1255 = FALSE; serv->using_cp1255 = FALSE;
@ -1836,7 +1833,7 @@ server_set_encoding (server *serv, char *new_encoding)
if (new_encoding) if (new_encoding)
{ {
serv->encoding = strdup (new_encoding); serv->encoding = g_strdup (new_encoding);
/* the serverlist GUI might have added a space /* the serverlist GUI might have added a space
and short description - remove it. */ and short description - remove it. */
space = strchr (serv->encoding, ' '); space = strchr (serv->encoding, ' ');
@ -1858,8 +1855,7 @@ server_new (void)
static int id = 0; static int id = 0;
server *serv; server *serv;
serv = malloc (sizeof (struct server)); serv = g_new0 (struct server, 1);
memset (serv, 0, sizeof (struct server));
/* use server.c and proto-irc.c functions */ /* use server.c and proto-irc.c functions */
server_fill_her_up (serv); server_fill_her_up (serv);
@ -1885,19 +1881,15 @@ is_server (server *serv)
void void
server_set_defaults (server *serv) server_set_defaults (server *serv)
{ {
if (serv->chantypes) g_free (serv->chantypes);
free (serv->chantypes); g_free (serv->chanmodes);
if (serv->chanmodes) g_free (serv->nick_prefixes);
free (serv->chanmodes); g_free (serv->nick_modes);
if (serv->nick_prefixes)
free (serv->nick_prefixes);
if (serv->nick_modes)
free (serv->nick_modes);
serv->chantypes = strdup ("#&!+"); serv->chantypes = g_strdup ("#&!+");
serv->chanmodes = strdup ("beI,k,l"); serv->chanmodes = g_strdup ("beI,k,l");
serv->nick_prefixes = strdup ("@%+"); serv->nick_prefixes = g_strdup ("@%+");
serv->nick_modes = strdup ("ohv"); serv->nick_modes = g_strdup ("ohv");
serv->nickcount = 1; serv->nickcount = 1;
serv->end_of_motd = FALSE; serv->end_of_motd = FALSE;
@ -2001,9 +1993,8 @@ server_away_free_messages (server *serv)
if (away->server == serv) if (away->server == serv)
{ {
away_list = g_slist_remove (away_list, away); away_list = g_slist_remove (away_list, away);
if (away->message) g_free (away->message);
free (away->message); g_free (away);
free (away);
next = away_list; next = away_list;
} }
list = next; list = next;
@ -2017,21 +2008,18 @@ server_away_save_message (server *serv, char *nick, char *msg)
if (away) /* Change message for known user */ if (away) /* Change message for known user */
{ {
if (away->message) g_free (away->message);
free (away->message); away->message = g_strdup (msg);
away->message = strdup (msg); }
} else else
{
/* Create brand new entry */ /* Create brand new entry */
{ away = g_new(struct away_msg, 1);
away = malloc (sizeof (struct away_msg));
if (away)
{
away->server = serv; away->server = serv;
safe_strcpy (away->nick, nick, sizeof (away->nick)); safe_strcpy (away->nick, nick, sizeof (away->nick));
away->message = strdup (msg); away->message = g_strdup (msg);
away_list = g_slist_prepend (away_list, away); away_list = g_slist_prepend (away_list, away);
} }
}
} }
void void
@ -2045,16 +2033,13 @@ server_free (server *serv)
serv->flush_queue (serv); serv->flush_queue (serv);
server_away_free_messages (serv); server_away_free_messages (serv);
free (serv->nick_modes); g_free (serv->nick_modes);
free (serv->nick_prefixes); g_free (serv->nick_prefixes);
free (serv->chanmodes); g_free (serv->chanmodes);
free (serv->chantypes); g_free (serv->chantypes);
if (serv->bad_nick_prefixes) g_free (serv->bad_nick_prefixes);
free (serv->bad_nick_prefixes); g_free (serv->last_away_reason);
if (serv->last_away_reason) g_free (serv->encoding);
free (serv->last_away_reason);
if (serv->encoding)
free (serv->encoding);
if (serv->favlist) if (serv->favlist)
g_slist_free_full (serv->favlist, (GDestroyNotify) servlist_favchan_free); g_slist_free_full (serv->favlist, (GDestroyNotify) servlist_favchan_free);
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
@ -2064,7 +2049,7 @@ server_free (server *serv)
fe_server_callback (serv); fe_server_callback (serv);
free (serv); g_free (serv);
notify_cleanup (); notify_cleanup ();
} }

View File

@ -566,9 +566,7 @@ servlist_favchan_copy (favchannel *fav)
{ {
favchannel *newfav; favchannel *newfav;
newfav = malloc (sizeof (favchannel)); newfav = g_new (favchannel, 1);
memset (newfav, 0, sizeof (favchannel));
newfav->name = g_strdup (fav->name); newfav->name = g_strdup (fav->name);
newfav->key = g_strdup (fav->key); /* g_strdup() can handle NULLs so no need to check it */ newfav->key = g_strdup (fav->key); /* g_strdup() can handle NULLs so no need to check it */
@ -924,9 +922,8 @@ servlist_server_add (ircnet *net, char *name)
{ {
ircserver *serv; ircserver *serv;
serv = malloc (sizeof (ircserver)); serv = g_new (ircserver, 1);
memset (serv, 0, sizeof (ircserver)); serv->hostname = g_strdup (name);
serv->hostname = strdup (name);
net->servlist = g_slist_append (net->servlist, serv); net->servlist = g_slist_append (net->servlist, serv);
@ -938,9 +935,8 @@ servlist_command_add (ircnet *net, char *cmd)
{ {
commandentry *entry; commandentry *entry;
entry = malloc (sizeof (commandentry)); entry = g_new (commandentry, 1);
memset (entry, 0, sizeof (commandentry)); entry->command = g_strdup (cmd);
entry->command = strdup (cmd);
net->commandlist = g_slist_append (net->commandlist, entry); net->commandlist = g_slist_append (net->commandlist, entry);
@ -952,9 +948,7 @@ servlist_favchan_listadd (GSList *chanlist, char *channel, char *key)
{ {
favchannel *chan; favchannel *chan;
chan = malloc (sizeof (favchannel)); chan = g_new (favchannel, 1);
memset (chan, 0, sizeof (favchannel));
chan->name = g_strdup (channel); chan->name = g_strdup (channel);
chan->key = g_strdup (key); chan->key = g_strdup (key);
chanlist = g_slist_append (chanlist, chan); chanlist = g_slist_append (chanlist, chan);
@ -990,8 +984,8 @@ servlist_favchan_add (ircnet *net, char *channel)
void void
servlist_server_remove (ircnet *net, ircserver *serv) servlist_server_remove (ircnet *net, ircserver *serv)
{ {
free (serv->hostname); g_free (serv->hostname);
free (serv); g_free (serv);
net->servlist = g_slist_remove (net->servlist, serv); net->servlist = g_slist_remove (net->servlist, serv);
} }
@ -1044,7 +1038,7 @@ free_and_clear (char *str)
char *orig = str; char *orig = str;
while (*str) while (*str)
*str++ = 0; *str++ = 0;
free (orig); g_free (orig);
} }
} }
@ -1072,25 +1066,18 @@ servlist_net_remove (ircnet *net)
servlist_server_remove_all (net); servlist_server_remove_all (net);
network_list = g_slist_remove (network_list, net); network_list = g_slist_remove (network_list, net);
if (net->nick) g_free (net->nick);
free (net->nick); g_free (net->nick2);
if (net->nick2) g_free (net->user);
free (net->nick2); g_free (net->real);
if (net->user)
free (net->user);
if (net->real)
free (net->real);
free_and_clear (net->pass); free_and_clear (net->pass);
if (net->favchanlist) if (net->favchanlist)
g_slist_free_full (net->favchanlist, (GDestroyNotify) servlist_favchan_free); g_slist_free_full (net->favchanlist, (GDestroyNotify) servlist_favchan_free);
if (net->commandlist) if (net->commandlist)
g_slist_free_full (net->commandlist, (GDestroyNotify) servlist_command_free); g_slist_free_full (net->commandlist, (GDestroyNotify) servlist_command_free);
if (net->comment) g_free (net->encoding);
free (net->comment); g_free (net->name);
if (net->encoding) g_free (net);
free (net->encoding);
free (net->name);
free (net);
/* for safety */ /* for safety */
list = serv_list; list = serv_list;
@ -1110,10 +1097,8 @@ servlist_net_add (char *name, char *comment, int prepend)
{ {
ircnet *net; ircnet *net;
net = malloc (sizeof (ircnet)); net = g_new0 (ircnet, 1);
memset (net, 0, sizeof (ircnet)); net->name = g_strdup (name);
net->name = strdup (name);
/* net->comment = strdup (comment);*/
net->flags = FLAG_CYCLE | FLAG_USE_GLOBAL | FLAG_USE_PROXY; net->flags = FLAG_CYCLE | FLAG_USE_GLOBAL | FLAG_USE_PROXY;
if (prepend) if (prepend)
@ -1210,25 +1195,25 @@ servlist_load (void)
switch (buf[0]) switch (buf[0])
{ {
case 'I': case 'I':
net->nick = strdup (buf + 2); net->nick = g_strdup (buf + 2);
break; break;
case 'i': case 'i':
net->nick2 = strdup (buf + 2); net->nick2 = g_strdup (buf + 2);
break; break;
case 'U': case 'U':
net->user = strdup (buf + 2); net->user = g_strdup (buf + 2);
break; break;
case 'R': case 'R':
net->real = strdup (buf + 2); net->real = g_strdup (buf + 2);
break; break;
case 'P': case 'P':
net->pass = strdup (buf + 2); net->pass = g_strdup (buf + 2);
break; break;
case 'L': case 'L':
net->logintype = atoi (buf + 2); net->logintype = atoi (buf + 2);
break; break;
case 'E': case 'E':
net->encoding = strdup (buf + 2); net->encoding = g_strdup (buf + 2);
break; break;
case 'F': case 'F':
net->flags = atoi (buf + 2); net->flags = atoi (buf + 2);
@ -1258,7 +1243,7 @@ servlist_load (void)
case 'A': case 'A':
if (!net->pass) if (!net->pass)
{ {
net->pass = strdup (buf + 2); net->pass = g_strdup (buf + 2);
if (!net->logintype) if (!net->logintype)
{ {
net->logintype = LOGIN_SASL; net->logintype = LOGIN_SASL;
@ -1267,7 +1252,7 @@ servlist_load (void)
case 'B': case 'B':
if (!net->pass) if (!net->pass)
{ {
net->pass = strdup (buf + 2); net->pass = g_strdup (buf + 2);
if (!net->logintype) if (!net->logintype)
{ {
net->logintype = LOGIN_NICKSERV; net->logintype = LOGIN_NICKSERV;

View File

@ -45,7 +45,6 @@ typedef struct ircnet
char *real; char *real;
char *pass; char *pass;
int logintype; int logintype;
char *comment;
char *encoding; char *encoding;
GSList *servlist; GSList *servlist;
GSList *commandlist; GSList *commandlist;

View File

@ -504,9 +504,7 @@ _SSL_check_common_name (X509 *cert, const char *host)
if (common_name_len < 0) if (common_name_len < 0)
return -1; return -1;
common_name = calloc (common_name_len + 1, 1); common_name = g_malloc0 (common_name_len + 1);
if (common_name == NULL)
return -1;
X509_NAME_get_text_by_NID (name, NID_commonName, common_name, common_name_len + 1); X509_NAME_get_text_by_NID (name, NID_commonName, common_name, common_name_len + 1);
@ -535,7 +533,7 @@ _SSL_check_common_name (X509 *cert, const char *host)
rv = 0; rv = 0;
out: out:
free(common_name); g_free(common_name);
return rv; return rv;
} }

View File

@ -83,7 +83,7 @@ scrollback_get_filename (session *sess)
buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "scrollback" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s.txt", get_xdir (), net, chan); buf = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "scrollback" G_DIR_SEPARATOR_S "%s" G_DIR_SEPARATOR_S "%s.txt", get_xdir (), net, chan);
else else
buf = NULL; buf = NULL;
free (chan); g_free (chan);
return buf; return buf;
} }
@ -406,7 +406,7 @@ log_create_filename (char *channame)
char *tmp, *ret; char *tmp, *ret;
int mbl; int mbl;
ret = tmp = strdup (channame); ret = tmp = g_strdup (channame);
while (*tmp) while (*tmp)
{ {
mbl = g_utf8_skip[((unsigned char *)tmp)[0]]; mbl = g_utf8_skip[((unsigned char *)tmp)[0]];
@ -542,7 +542,7 @@ log_create_pathname (char *servname, char *channame, char *netname)
if (!netname) if (!netname)
{ {
netname = strdup ("NETWORK"); netname = g_strdup ("NETWORK");
} }
else else
{ {
@ -552,7 +552,7 @@ log_create_pathname (char *servname, char *channame, char *netname)
/* first, everything is in UTF-8 */ /* first, everything is in UTF-8 */
if (!rfc_casecmp (channame, servname)) if (!rfc_casecmp (channame, servname))
{ {
channame = strdup ("server"); channame = g_strdup ("server");
} }
else else
{ {
@ -560,8 +560,8 @@ log_create_pathname (char *servname, char *channame, char *netname)
} }
log_insert_vars (fname, sizeof (fname), prefs.hex_irc_logmask, channame, netname, servname); log_insert_vars (fname, sizeof (fname), prefs.hex_irc_logmask, channame, netname, servname);
free (channame); g_free (channame);
free (netname); g_free (netname);
/* insert time/date */ /* insert time/date */
now = time (NULL); now = time (NULL);
@ -803,8 +803,6 @@ iso_8859_1_to_utf8 (unsigned char *text, int len, gsize *bytes_written)
/* worst case scenario: every byte turns into 3 bytes */ /* worst case scenario: every byte turns into 3 bytes */
res = output = g_malloc ((len * 3) + 1); res = output = g_malloc ((len * 3) + 1);
if (!output)
return NULL;
while (len) while (len)
{ {
@ -1565,14 +1563,13 @@ pevent_load_defaults ()
for (i = 0; i < NUM_XP; i++) for (i = 0; i < NUM_XP; i++)
{ {
if (pntevts_text[i]) g_free (pntevts_text[i]);
free (pntevts_text[i]);
/* make-te.c sets this 128 flag (DON'T call gettext() flag) */ /* make-te.c sets this 128 flag (DON'T call gettext() flag) */
if (te[i].num_args & 128) if (te[i].num_args & 128)
pntevts_text[i] = strdup (te[i].def); pntevts_text[i] = g_strdup (te[i].def);
else else
pntevts_text[i] = strdup (_(te[i].def)); pntevts_text[i] = g_strdup (_(te[i].def));
} }
} }
@ -1584,19 +1581,18 @@ pevent_make_pntevts ()
for (i = 0; i < NUM_XP; i++) for (i = 0; i < NUM_XP; i++)
{ {
if (pntevts[i] != NULL) g_free (pntevts[i]);
free (pntevts[i]);
if (pevt_build_string (pntevts_text[i], &(pntevts[i]), &m) != 0) if (pevt_build_string (pntevts_text[i], &(pntevts[i]), &m) != 0)
{ {
snprintf (out, sizeof (out), snprintf (out, sizeof (out),
_("Error parsing event %s.\nLoading default."), te[i].name); _("Error parsing event %s.\nLoading default."), te[i].name);
fe_message (out, FE_MSG_WARN); fe_message (out, FE_MSG_WARN);
free (pntevts_text[i]); g_free (pntevts_text[i]);
/* make-te.c sets this 128 flag (DON'T call gettext() flag) */ /* make-te.c sets this 128 flag (DON'T call gettext() flag) */
if (te[i].num_args & 128) if (te[i].num_args & 128)
pntevts_text[i] = strdup (te[i].def); pntevts_text[i] = g_strdup (te[i].def);
else else
pntevts_text[i] = strdup (_(te[i].def)); pntevts_text[i] = g_strdup (_(te[i].def));
if (pevt_build_string (pntevts_text[i], &(pntevts[i]), &m) != 0) if (pevt_build_string (pntevts_text[i], &(pntevts[i]), &m) != 0)
{ {
fprintf (stderr, fprintf (stderr,
@ -1618,22 +1614,17 @@ pevent_make_pntevts ()
static void static void
pevent_trigger_load (int *i_penum, char **i_text, char **i_snd) pevent_trigger_load (int *i_penum, char **i_text, char **i_snd)
{ {
int penum = *i_penum, len; int penum = *i_penum;
char *text = *i_text, *snd = *i_snd; char *text = *i_text, *snd = *i_snd;
if (penum != -1 && text != NULL) if (penum != -1 && text != NULL)
{ {
len = strlen (text) + 1; g_free (pntevts_text[penum]);
if (pntevts_text[penum]) pntevts_text[penum] = g_strdup (text);
free (pntevts_text[penum]);
pntevts_text[penum] = malloc (len);
memcpy (pntevts_text[penum], text, len);
} }
if (text) g_free (text);
free (text); g_free (snd);
if (snd)
free (snd);
*i_text = NULL; *i_text = NULL;
*i_snd = NULL; *i_snd = NULL;
*i_penum = 0; *i_penum = 0;
@ -1686,7 +1677,7 @@ pevent_load (char *filename)
close (fd); close (fd);
return 1; return 1;
} }
ibuf = malloc (st.st_size); ibuf = g_malloc (st.st_size);
read (fd, ibuf, st.st_size); read (fd, ibuf, st.st_size);
close (fd); close (fd);
@ -1702,8 +1693,6 @@ pevent_load (char *filename)
continue; continue;
*ofs = 0; *ofs = 0;
ofs++; ofs++;
/*if (*ofs == 0)
continue;*/
if (strcmp (buf, "event_name") == 0) if (strcmp (buf, "event_name") == 0)
{ {
@ -1713,53 +1702,16 @@ pevent_load (char *filename)
continue; continue;
} else if (strcmp (buf, "event_text") == 0) } else if (strcmp (buf, "event_text") == 0)
{ {
if (text) g_free (text);
free (text); text = g_strdup (ofs);
continue;
#if 0
/* This allows updating of old strings. We don't use new defaults
if the user has customized the strings (.e.g a text theme).
Hash of the old default is enough to identify and replace it.
This only works in English. */
switch (g_str_hash (ofs))
{
case 0x526743a4:
/* %C08,02 Hostmask PRIV NOTI CHAN CTCP INVI UNIG %O */
text = strdup (te[XP_TE_IGNOREHEADER].def);
break;
case 0xe91bc9c2:
/* %C08,02 %O */
text = strdup (te[XP_TE_IGNOREFOOTER].def);
break;
case 0x1fbfdf22:
/* -%C10-%C11-%O$tDCC RECV: Cannot open $1 for writing - aborting. */
text = strdup (te[XP_TE_DCCFILEERR].def);
break;
default:
text = strdup (ofs);
} }
#else
text = strdup (ofs);
#endif
continue;
}/* else if (strcmp (buf, "event_sound") == 0)
{
if (snd)
free (snd);
snd = strdup (ofs);
continue;
}*/
continue; continue;
} }
pevent_trigger_load (&penum, &text, &snd); pevent_trigger_load (&penum, &text, &snd);
free (ibuf); g_free (ibuf);
return 0; return 0;
} }
@ -1777,9 +1729,9 @@ pevent_check_all_loaded ()
gtkutil_simpledialog(out); */ gtkutil_simpledialog(out); */
/* make-te.c sets this 128 flag (DON'T call gettext() flag) */ /* make-te.c sets this 128 flag (DON'T call gettext() flag) */
if (te[i].num_args & 128) if (te[i].num_args & 128)
pntevts_text[i] = strdup (te[i].def); pntevts_text[i] = g_strdup (te[i].def);
else else
pntevts_text[i] = strdup (_(te[i].def)); pntevts_text[i] = g_strdup (_(te[i].def));
} }
} }
} }
@ -1896,7 +1848,7 @@ pevt_build_string (const char *input, char **output, int *max_arg)
int oi, ii, max = -1, len, x; int oi, ii, max = -1, len, x;
len = strlen (input); len = strlen (input);
i = malloc (len + 1); i = g_malloc (len + 1);
memcpy (i, input, len + 1); memcpy (i, input, len + 1);
check_special_chars (i, TRUE); check_special_chars (i, TRUE);
@ -1921,14 +1873,14 @@ pevt_build_string (const char *input, char **output, int *max_arg)
} }
if (oi > 0) if (oi > 0)
{ {
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1)); s = g_new (struct pevt_stage1, 1);
if (base == NULL) if (base == NULL)
base = s; base = s;
if (last != NULL) if (last != NULL)
last->next = s; last->next = s;
last = s; last = s;
s->next = NULL; s->next = NULL;
s->data = malloc (oi + sizeof (int) + 1); s->data = g_malloc (oi + sizeof (int) + 1);
s->len = oi + sizeof (int) + 1; s->len = oi + sizeof (int) + 1;
clen += oi + sizeof (int) + 1; clen += oi + sizeof (int) + 1;
s->data[0] = 0; s->data[0] = 0;
@ -1939,11 +1891,12 @@ pevt_build_string (const char *input, char **output, int *max_arg)
if (ii == len) if (ii == len)
{ {
fe_message ("String ends with a $", FE_MSG_WARN); fe_message ("String ends with a $", FE_MSG_WARN);
return 1; goto err;
} }
d = i[ii++]; d = i[ii++];
if (d == 'a') if (d == 'a')
{ /* Hex value */ {
/* Hex value */
x = 0; x = 0;
if (ii == len) if (ii == len)
goto a_len_error; goto a_len_error;
@ -1967,24 +1920,22 @@ pevt_build_string (const char *input, char **output, int *max_arg)
a_len_error: a_len_error:
fe_message ("String ends in $a", FE_MSG_WARN); fe_message ("String ends in $a", FE_MSG_WARN);
free (i); goto err;
return 1;
a_range_error: a_range_error:
fe_message ("$a value is greater than 255", FE_MSG_WARN); fe_message ("$a value is greater than 255", FE_MSG_WARN);
free (i); goto err;
return 1;
} }
if (d == 't') if (d == 't')
{ {
/* Tab - if tabnicks is set then write '\t' else ' ' */ /* Tab - if tabnicks is set then write '\t' else ' ' */
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1)); s = g_new (struct pevt_stage1, 1);
if (base == NULL) if (base == NULL)
base = s; base = s;
if (last != NULL) if (last != NULL)
last->next = s; last->next = s;
last = s; last = s;
s->next = NULL; s->next = NULL;
s->data = malloc (1); s->data = g_malloc (1);
s->len = 1; s->len = 1;
clen += 1; clen += 1;
s->data[0] = 3; s->data[0] = 3;
@ -1995,20 +1946,19 @@ pevt_build_string (const char *input, char **output, int *max_arg)
{ {
snprintf (o, sizeof (o), "Error, invalid argument $%c\n", d); snprintf (o, sizeof (o), "Error, invalid argument $%c\n", d);
fe_message (o, FE_MSG_WARN); fe_message (o, FE_MSG_WARN);
free (i); goto err;
return 1;
} }
d -= '0'; d -= '0';
if (max < d) if (max < d)
max = d; max = d;
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1)); s = g_new (struct pevt_stage1, 1);
if (base == NULL) if (base == NULL)
base = s; base = s;
if (last != NULL) if (last != NULL)
last->next = s; last->next = s;
last = s; last = s;
s->next = NULL; s->next = NULL;
s->data = malloc (2); s->data = g_malloc (2);
s->len = 2; s->len = 2;
clen += 2; clen += 2;
s->data[0] = 1; s->data[0] = 1;
@ -2016,14 +1966,14 @@ pevt_build_string (const char *input, char **output, int *max_arg)
} }
if (oi > 0) if (oi > 0)
{ {
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1)); s = g_new (struct pevt_stage1, 1);
if (base == NULL) if (base == NULL)
base = s; base = s;
if (last != NULL) if (last != NULL)
last->next = s; last->next = s;
last = s; last = s;
s->next = NULL; s->next = NULL;
s->data = malloc (oi + sizeof (int) + 1); s->data = g_malloc (oi + sizeof (int) + 1);
s->len = oi + sizeof (int) + 1; s->len = oi + sizeof (int) + 1;
clen += oi + sizeof (int) + 1; clen += oi + sizeof (int) + 1;
s->data[0] = 0; s->data[0] = 0;
@ -2031,41 +1981,55 @@ pevt_build_string (const char *input, char **output, int *max_arg)
memcpy (&(s->data[1 + sizeof (int)]), o, oi); memcpy (&(s->data[1 + sizeof (int)]), o, oi);
oi = 0; oi = 0;
} }
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1)); s = g_new (struct pevt_stage1, 1);
if (base == NULL) if (base == NULL)
base = s; base = s;
if (last != NULL) if (last != NULL)
last->next = s; last->next = s;
last = s; last = s;
s->next = NULL; s->next = NULL;
s->data = malloc (1); s->data = g_malloc (1);
s->len = 1; s->len = 1;
clen += 1; clen += 1;
s->data[0] = 2; s->data[0] = 2;
oi = 0; oi = 0;
s = base; s = base;
obuf = malloc (clen); obuf = g_malloc (clen);
while (s) while (s)
{ {
next = s->next; next = s->next;
memcpy (&obuf[oi], s->data, s->len); memcpy (&obuf[oi], s->data, s->len);
oi += s->len; oi += s->len;
free (s->data); g_free (s->data);
free (s); g_free (s);
s = next; s = next;
} }
free (i); g_free (i);
if (max_arg) if (max_arg)
*max_arg = max; *max_arg = max;
if (output) if (output)
*output = obuf; *output = obuf;
else else
free (obuf); g_free (obuf);
return 0; return 0;
err:
while (s)
{
next = s->next;
g_free (s->data);
g_free (s);
s = next;
}
g_free(i);
return 1;
} }
@ -2356,9 +2320,8 @@ sound_load_event (char *evt, char *file)
if (file[0] && pevent_find (evt, &i) != -1) if (file[0] && pevent_find (evt, &i) != -1)
{ {
if (sound_files[i]) g_free (sound_files[i]);
free (sound_files[i]); sound_files[i] = g_strdup (file);
sound_files[i] = strdup (file);
} }
} }

View File

@ -42,7 +42,7 @@ struct _tree
tree * tree *
tree_new (tree_cmp_func *cmp, void *data) tree_new (tree_cmp_func *cmp, void *data)
{ {
tree *t = calloc (1, sizeof (tree)); tree *t = g_new0 (tree, 1);
t->cmp = cmp; t->cmp = cmp;
t->data = data; t->data = data;
return t; return t;
@ -53,9 +53,8 @@ tree_destroy (tree *t)
{ {
if (t) if (t)
{ {
if (t->array) g_free (t->array);
free (t->array); g_free (t);
free (t);
} }
} }

View File

@ -20,6 +20,8 @@
#ifndef HEXCHAT_TREE_H #ifndef HEXCHAT_TREE_H
#define HEXCHAT_TREE_H #define HEXCHAT_TREE_H
#include <glib.h>
typedef struct _tree tree; typedef struct _tree tree;
typedef int (tree_cmp_func) (const void *keya, const void *keyb, void *data); typedef int (tree_cmp_func) (const void *keya, const void *keyb, void *data);

View File

@ -53,7 +53,7 @@ static gboolean match_path (const char *word, int *start, int *end);
static int static int
url_free (char *url, void *data) url_free (char *url, void *data)
{ {
free (url); g_free (url);
return TRUE; return TRUE;
} }
@ -124,13 +124,7 @@ url_add (char *urltext, int len)
return; return;
} }
data = malloc (len + 1); data = g_strndup (urltext, len);
if (!data)
{
return;
}
memcpy (data, urltext, len);
data[len] = 0;
if (data[len - 1] == '.') /* chop trailing dot */ if (data[len - 1] == '.') /* chop trailing dot */
{ {
@ -151,7 +145,7 @@ url_add (char *urltext, int len)
/* the URL is saved already, only continue if we need the URL grabber too */ /* the URL is saved already, only continue if we need the URL grabber too */
if (!prefs.hex_url_grabber) if (!prefs.hex_url_grabber)
{ {
free (data); g_free (data);
return; return;
} }
@ -163,7 +157,7 @@ url_add (char *urltext, int len)
if (url_find (data)) if (url_find (data))
{ {
free (data); g_free (data);
return; return;
} }
@ -180,7 +174,7 @@ url_add (char *urltext, int len)
pos = tree_remove_at_pos (url_tree, 0); pos = tree_remove_at_pos (url_tree, 0);
g_tree_remove (url_btree, pos); g_tree_remove (url_btree, pos);
free (pos); g_free (pos);
} }
} }

View File

@ -121,13 +121,12 @@ userlist_set_account (struct session *sess, char *nick, char *account)
user = userlist_find (sess, nick); user = userlist_find (sess, nick);
if (user) if (user)
{ {
if (user->account) g_free (user->account);
free (user->account);
if (strcmp (account, "*") == 0) if (strcmp (account, "*") == 0)
user->account = NULL; user->account = NULL;
else else
user->account = strdup (account); user->account = g_strdup (account);
/* gui doesnt currently reflect login status, maybe later /* gui doesnt currently reflect login status, maybe later
fe_userlist_rehash (sess, user); */ fe_userlist_rehash (sess, user); */
@ -148,14 +147,14 @@ userlist_add_hostname (struct session *sess, char *nick, char *hostname,
{ {
if (prefs.hex_gui_ulist_show_hosts) if (prefs.hex_gui_ulist_show_hosts)
do_rehash = TRUE; do_rehash = TRUE;
user->hostname = strdup (hostname); user->hostname = g_strdup (hostname);
} }
if (!user->realname && realname && *realname) if (!user->realname && realname && *realname)
user->realname = strdup (realname); user->realname = g_strdup (realname);
if (!user->servername && servername) if (!user->servername && servername)
user->servername = strdup (servername); user->servername = g_strdup (servername);
if (!user->account && account && strcmp (account, "0") != 0) if (!user->account && account && strcmp (account, "0") != 0)
user->account = strdup (account); user->account = g_strdup (account);
if (away != 0xff) if (away != 0xff)
{ {
if (user->away != away) if (user->away != away)
@ -175,15 +174,11 @@ userlist_add_hostname (struct session *sess, char *nick, char *hostname,
static int static int
free_user (struct User *user, gpointer data) free_user (struct User *user, gpointer data)
{ {
if (user->realname) g_free (user->realname);
free (user->realname); g_free (user->hostname);
if (user->hostname) g_free (user->servername);
free (user->hostname); g_free (user->account);
if (user->servername) g_free (user);
free (user->servername);
if (user->account)
free (user->account);
free (user);
return TRUE; return TRUE;
} }
@ -397,8 +392,7 @@ userlist_add (struct session *sess, char *name, char *hostname,
notify_set_online (sess->server, name + prefix_chars, tags_data); notify_set_online (sess->server, name + prefix_chars, tags_data);
user = malloc (sizeof (struct User)); user = g_new0 (struct User, 1);
memset (user, 0, sizeof (struct User));
user->access = acc; user->access = acc;
@ -408,7 +402,7 @@ userlist_add (struct session *sess, char *name, char *hostname,
/* add it to our linked list */ /* add it to our linked list */
if (hostname) if (hostname)
user->hostname = strdup (hostname); user->hostname = g_strdup (hostname);
safe_strcpy (user->nick, name + prefix_chars, NICKLEN); safe_strcpy (user->nick, name + prefix_chars, NICKLEN);
/* is it me? */ /* is it me? */
if (!sess->server->p_cmp (user->nick, sess->server->nick)) if (!sess->server->p_cmp (user->nick, sess->server->nick))
@ -417,9 +411,9 @@ userlist_add (struct session *sess, char *name, char *hostname,
if (sess->server->have_extjoin) if (sess->server->have_extjoin)
{ {
if (account && *account) if (account && *account)
user->account = strdup (account); user->account = g_strdup (account);
if (realname && *realname) if (realname && *realname)
user->realname = strdup (realname); user->realname = g_strdup (realname);
} }
row = userlist_insertname (sess, user); row = userlist_insertname (sess, user);
@ -427,13 +421,10 @@ userlist_add (struct session *sess, char *name, char *hostname,
/* duplicate? some broken servers trigger this */ /* duplicate? some broken servers trigger this */
if (row == -1) if (row == -1)
{ {
if (user->hostname) g_free (user->hostname);
free (user->hostname); g_free (user->account);
if (user->account) g_free (user->realname);
free (user->account); g_free (user);
if (user->realname)
free (user->realname);
free (user);
return; return;
} }

View File

@ -619,8 +619,6 @@ get_sys_str (int with_cpu)
if (buf) if (buf)
return buf; return buf;
buf = malloc (128);
uname (&un); uname (&un);
#if defined (USING_LINUX) || defined (USING_FREEBSD) || defined (__APPLE__) || defined (__CYGWIN__) #if defined (USING_LINUX) || defined (USING_FREEBSD) || defined (__APPLE__) || defined (__CYGWIN__)
@ -629,14 +627,16 @@ get_sys_str (int with_cpu)
{ {
double cpuspeed = ( mhz > 1000 ) ? mhz / 1000 : mhz; double cpuspeed = ( mhz > 1000 ) ? mhz / 1000 : mhz;
const char *cpuspeedstr = ( mhz > 1000 ) ? "GHz" : "MHz"; const char *cpuspeedstr = ( mhz > 1000 ) ? "GHz" : "MHz";
snprintf (buf, 128, buf = g_strdup_printf (
(cpus == 1) ? "%s %s [%s/%.2f%s]" : "%s %s [%s/%.2f%s/SMP]", (cpus == 1) ? "%s %s [%s/%.2f%s]" : "%s %s [%s/%.2f%s/SMP]",
un.sysname, un.release, un.machine, un.sysname, un.release, un.machine,
cpuspeed, cpuspeedstr); cpuspeed, cpuspeedstr);
} }
else else
buf = g_strdup_printf ("%s %s", un.sysname, un.release);
#else
buf = g_strdup_printf ("%s %s", un.sysname, un.release);
#endif #endif
snprintf (buf, 128, "%s %s", un.sysname, un.release);
return buf; return buf;
} }
@ -1503,7 +1503,7 @@ parse_dh (char *str, DH **dh_out, unsigned char **secret_out, int *keysize_out)
{ {
DH *dh; DH *dh;
guchar *data, *decoded_data; guchar *data, *decoded_data;
guchar *secret; guchar *secret = NULL;
gsize data_len; gsize data_len;
guint size; guint size;
guint16 size16; guint16 size16;
@ -1555,7 +1555,7 @@ parse_dh (char *str, DH **dh_out, unsigned char **secret_out, int *keysize_out)
if (!(DH_generate_key (dh))) if (!(DH_generate_key (dh)))
goto fail; goto fail;
secret = (unsigned char*)malloc (DH_size(dh)); secret = g_malloc (DH_size (dh));
key_size = DH_compute_key (secret, pubkey, dh); key_size = DH_compute_key (secret, pubkey, dh);
if (key_size == -1) if (key_size == -1)
goto fail; goto fail;
@ -1568,7 +1568,9 @@ parse_dh (char *str, DH **dh_out, unsigned char **secret_out, int *keysize_out)
return 1; return 1;
fail: fail:
g_free (secret);
g_free (decoded_data); g_free (decoded_data);
return 0; return 0;
} }
@ -1576,7 +1578,7 @@ char *
encode_sasl_pass_blowfish (char *user, char *pass, char *data) encode_sasl_pass_blowfish (char *user, char *pass, char *data)
{ {
DH *dh; DH *dh;
char *response, *ret; char *response, *ret = NULL;
unsigned char *secret; unsigned char *secret;
unsigned char *encrypted_pass; unsigned char *encrypted_pass;
char *plain_pass; char *plain_pass;
@ -1591,10 +1593,8 @@ encode_sasl_pass_blowfish (char *user, char *pass, char *data)
return NULL; return NULL;
BF_set_key (&key, key_size, secret); BF_set_key (&key, key_size, secret);
encrypted_pass = (guchar*)malloc (pass_len); encrypted_pass = g_malloc0 (pass_len);
memset (encrypted_pass, 0, pass_len); plain_pass = g_malloc0 (pass_len);
plain_pass = (char*)malloc (pass_len);
memset (plain_pass, 0, pass_len);
memcpy (plain_pass, pass, strlen(pass)); memcpy (plain_pass, pass, strlen(pass));
out_ptr = (char*)encrypted_pass; out_ptr = (char*)encrypted_pass;
in_ptr = (char*)plain_pass; in_ptr = (char*)plain_pass;
@ -1604,7 +1604,7 @@ encode_sasl_pass_blowfish (char *user, char *pass, char *data)
/* Create response */ /* Create response */
length = 2 + BN_num_bytes (dh->pub_key) + pass_len + user_len + 1; length = 2 + BN_num_bytes (dh->pub_key) + pass_len + user_len + 1;
response = (char*)malloc (length); response = g_malloc0 (length);
out_ptr = response; out_ptr = response;
/* our key */ /* our key */
@ -1623,11 +1623,12 @@ encode_sasl_pass_blowfish (char *user, char *pass, char *data)
ret = g_base64_encode ((const guchar*)response, length); ret = g_base64_encode ((const guchar*)response, length);
DH_free (dh); g_free (response);
free (plain_pass);
free (encrypted_pass); DH_free(dh);
free (secret); g_free (plain_pass);
free (response); g_free (encrypted_pass);
g_free (secret);
return ret; return ret;
} }
@ -1653,10 +1654,8 @@ encode_sasl_pass_aes (char *user, char *pass, char *data)
if (!parse_dh (data, &dh, &secret, &key_size)) if (!parse_dh (data, &dh, &secret, &key_size))
return NULL; return NULL;
encrypted_userpass = (guchar*)malloc (userpass_len); encrypted_userpass = g_malloc0 (userpass_len);
memset (encrypted_userpass, 0, userpass_len); plain_userpass = g_malloc0 (userpass_len);
plain_userpass = (guchar*)malloc (userpass_len);
memset (plain_userpass, 0, userpass_len);
/* create message */ /* create message */
/* format of: <username>\0<password>\0<padding> */ /* format of: <username>\0<password>\0<padding> */
@ -1687,7 +1686,7 @@ encode_sasl_pass_aes (char *user, char *pass, char *data)
/* Create response */ /* Create response */
/* format of: <size pubkey><pubkey><iv (always 16 bytes)><ciphertext> */ /* format of: <size pubkey><pubkey><iv (always 16 bytes)><ciphertext> */
length = 2 + key_size + sizeof(iv) + userpass_len; length = 2 + key_size + sizeof(iv) + userpass_len;
response = (char*)malloc (length); response = g_malloc (length);
out_ptr = response; out_ptr = response;
/* our key */ /* our key */
@ -1708,11 +1707,10 @@ encode_sasl_pass_aes (char *user, char *pass, char *data)
end: end:
DH_free (dh); DH_free (dh);
free (plain_userpass); g_free (plain_userpass);
free (encrypted_userpass); g_free (encrypted_userpass);
free (secret); g_free (secret);
if (response) g_free (response);
free (response);
return ret; return ret;
} }

View File

@ -305,6 +305,7 @@ _wopendir(
{ {
_WDIR *dirp = NULL; _WDIR *dirp = NULL;
int error; int error;
DWORD n;
/* Must have directory name */ /* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') { if (dirname == NULL || dirname[0] == '\0') {
@ -313,10 +314,7 @@ _wopendir(
} }
/* Allocate new _WDIR structure */ /* Allocate new _WDIR structure */
dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); dirp = (_WDIR*) g_new (struct _WDIR, 1);
if (dirp != NULL) {
DWORD n;
/* Reset _WDIR structure */ /* Reset _WDIR structure */
dirp->handle = INVALID_HANDLE_VALUE; dirp->handle = INVALID_HANDLE_VALUE;
dirp->patt = NULL; dirp->patt = NULL;
@ -326,9 +324,7 @@ _wopendir(
n = GetFullPathNameW (dirname, 0, NULL, NULL); n = GetFullPathNameW (dirname, 0, NULL, NULL);
/* Allocate room for absolute directory name and search pattern */ /* Allocate room for absolute directory name and search pattern */
dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16); dirp->patt = g_malloc (sizeof (wchar_t) * n + 16);
if (dirp->patt) {
/* /*
* Convert relative directory name to an absolute one. This * Convert relative directory name to an absolute one. This
* allows rewinddir() to function correctly even when current * allows rewinddir() to function correctly even when current
@ -373,16 +369,6 @@ _wopendir(
error = 1; error = 1;
} }
} else {
/* Cannot allocate memory for search pattern */
error = 1;
}
} else {
/* Cannot allocate _WDIR structure */
error = 1;
}
/* Clean up in case of error */ /* Clean up in case of error */
if (error && dirp) { if (error && dirp) {
_wclosedir (dirp); _wclosedir (dirp);
@ -472,13 +458,11 @@ _wclosedir(
} }
/* Release search pattern */ /* Release search pattern */
if (dirp->patt) { g_free (dirp->patt);
free (dirp->patt);
dirp->patt = NULL; dirp->patt = NULL;
}
/* Release directory structure */ /* Release directory structure */
free (dirp); g_free (dirp);
ok = /*success*/0; ok = /*success*/0;
} else { } else {
@ -579,6 +563,8 @@ opendir(
{ {
struct DIR *dirp; struct DIR *dirp;
int error; int error;
wchar_t wname[PATH_MAX + 1];
size_t n;
/* Must have directory name */ /* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') { if (dirname == NULL || dirname[0] == '\0') {
@ -587,10 +573,7 @@ opendir(
} }
/* Allocate memory for DIR structure */ /* Allocate memory for DIR structure */
dirp = (DIR*) malloc (sizeof (struct DIR)); dirp = (DIR*) g_new (struct DIR, 1);
if (dirp) {
wchar_t wname[PATH_MAX + 1];
size_t n;
/* Convert directory name to wide-character string */ /* Convert directory name to wide-character string */
error = dirent_mbstowcs_s( error = dirent_mbstowcs_s(
@ -617,14 +600,9 @@ opendir(
error = 1; error = 1;
} }
} else {
/* Cannot allocate DIR structure */
error = 1;
}
/* Clean up in case of error */ /* Clean up in case of error */
if (error && dirp) { if (error != 0) {
free (dirp); g_free (dirp);
dirp = NULL; dirp = NULL;
} }
@ -733,14 +711,14 @@ closedir(
DIR *dirp) DIR *dirp)
{ {
int ok; int ok;
if (dirp) { if (dirp != NULL) {
/* Close wide-character directory stream */ /* Close wide-character directory stream */
ok = _wclosedir (dirp->wdirp); ok = _wclosedir (dirp->wdirp);
dirp->wdirp = NULL; dirp->wdirp = NULL;
/* Release multi-byte character version */ /* Release multi-byte character version */
free (dirp); g_free (dirp);
} else { } else {

View File

@ -491,7 +491,7 @@ banlist_unban_inner (gpointer none, banlist_info *banl, int mode_num)
if (!gtk_tree_model_get_iter_first (model, &iter)) if (!gtk_tree_model_get_iter_first (model, &iter))
return 0; return 0;
masks = g_malloc (sizeof (char *) * banl->line_ct); masks = g_new (char *, banl->line_ct);
num_sel = 0; num_sel = 0;
do do
{ {
@ -577,17 +577,17 @@ static void
banlist_add_selected_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) banlist_add_selected_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{ {
GSList **lp = data; GSList **lp = data;
GSList *list = NULL;
GtkTreeIter *copy; GtkTreeIter *copy;
if (!lp) return; if (lp == NULL)
list = *lp; {
copy = g_malloc (sizeof (GtkTreeIter)); return;
g_return_if_fail (copy != NULL); }
copy = g_new (GtkTreeIter, 1);
*copy = *iter; *copy = *iter;
list = g_slist_append (list, copy); *lp = g_slist_append (*lp, copy);
*(GSList **)data = list;
} }
static void static void
@ -786,14 +786,9 @@ banlist_opengui (struct session *sess)
return; return;
} }
if (!sess->res->banlist) if (sess->res->banlist == NULL)
{ {
sess->res->banlist = g_malloc0 (sizeof (banlist_info)); sess->res->banlist = g_new0 (banlist_info, 1);
if (!sess->res->banlist)
{
fe_message (_("Banlist initialization failed."), FE_MSG_ERROR);
return;
}
} }
banl = sess->res->banlist; banl = sess->res->banlist;
if (banl->window) if (banl->window)

View File

@ -148,7 +148,7 @@ chanlist_data_free (server *serv)
data = rows->data; data = rows->data;
g_free (data->topic); g_free (data->topic);
g_free (data->collation_key); g_free (data->collation_key);
free (data); g_free (data);
} }
g_slist_free (serv->gui->chanlist_data_stored_rows); g_slist_free (serv->gui->chanlist_data_stored_rows);
@ -370,7 +370,7 @@ fe_add_chan_list (server *serv, char *chan, char *users, char *topic)
int len = strlen (chan) + 1; int len = strlen (chan) + 1;
/* we allocate the struct and channel string in one go */ /* we allocate the struct and channel string in one go */
next_row = malloc (sizeof (chanlistrow) + len); next_row = g_malloc (sizeof (chanlistrow) + len);
memcpy (((char *)next_row) + sizeof (chanlistrow), chan, len); memcpy (((char *)next_row) + sizeof (chanlistrow), chan, len);
next_row->topic = strip_color (topic, -1, STRIP_ALL); next_row->topic = strip_color (topic, -1, STRIP_ALL);
next_row->collation_key = g_utf8_collate_key (chan, len-1); next_row->collation_key = g_utf8_collate_key (chan, len-1);

View File

@ -111,9 +111,8 @@ truncate_tab_name (char *name, int max)
if (max > 2 && g_utf8_strlen (name, -1) > max) if (max > 2 && g_utf8_strlen (name, -1) > max)
{ {
/* truncate long channel names */ /* truncate long channel names */
buf = malloc (strlen (name) + 4); buf = g_malloc (strlen (name) + 4);
strcpy (buf, name); g_utf8_strncpy (buf, name, max);
g_utf8_offset_to_pointer (buf, max)[0] = 0;
strcat (buf, ".."); strcat (buf, "..");
return buf; return buf;
} }
@ -231,7 +230,7 @@ chanview_free_ch (chanview *cv, GtkTreeIter *iter)
chan *ch; chan *ch;
gtk_tree_model_get (GTK_TREE_MODEL (cv->store), iter, COL_CHAN, &ch, -1); gtk_tree_model_get (GTK_TREE_MODEL (cv->store), iter, COL_CHAN, &ch, -1);
free (ch); g_free (ch);
} }
static void static void
@ -251,7 +250,7 @@ chanview_destroy (chanview *cv)
gtk_widget_destroy (cv->box); gtk_widget_destroy (cv->box);
chanview_destroy_store (cv); chanview_destroy_store (cv);
free (cv); g_free (cv);
} }
static void static void
@ -267,7 +266,7 @@ chanview_new (int type, int trunc_len, gboolean sort, gboolean use_icons,
{ {
chanview *cv; chanview *cv;
cv = calloc (1, sizeof (chanview)); cv = g_new0 (chanview, 1);
cv->store = gtk_tree_store_new (4, G_TYPE_STRING, G_TYPE_POINTER, cv->store = gtk_tree_store_new (4, G_TYPE_STRING, G_TYPE_POINTER,
PANGO_TYPE_ATTR_LIST, GDK_TYPE_PIXBUF); PANGO_TYPE_ATTR_LIST, GDK_TYPE_PIXBUF);
cv->style = style; cv->style = style;
@ -368,7 +367,7 @@ chanview_add_real (chanview *cv, char *name, void *family, void *userdata,
if (!ch) if (!ch)
{ {
ch = calloc (1, sizeof (chan)); ch = g_new0 (chan, 1);
ch->userdata = userdata; ch->userdata = userdata;
ch->family = family; ch->family = family;
ch->cv = cv; ch->cv = cv;
@ -401,7 +400,7 @@ chanview_add (chanview *cv, char *name, void *family, void *userdata, gboolean a
ret = chanview_add_real (cv, new_name, family, userdata, allow_closure, tag, icon, NULL, NULL); ret = chanview_add_real (cv, new_name, family, userdata, allow_closure, tag, icon, NULL, NULL);
if (new_name != name) if (new_name != name)
free (new_name); g_free (new_name);
return ret; return ret;
} }
@ -492,7 +491,7 @@ chan_rename (chan *ch, char *name, int trunc_len)
ch->cv->trunc_len = trunc_len; ch->cv->trunc_len = trunc_len;
if (new_name != name) if (new_name != name)
free (new_name); g_free (new_name);
} }
/* this thing is overly complicated */ /* this thing is overly complicated */
@ -645,7 +644,7 @@ chan_remove (chan *ch, gboolean force)
ch->cv->size--; ch->cv->size--;
gtk_tree_store_remove (ch->cv->store, &ch->iter); gtk_tree_store_remove (ch->cv->store, &ch->iter);
free (ch); g_free (ch);
return TRUE; return TRUE;
} }

View File

@ -727,7 +727,7 @@ custom_list_resort (CustomList * custom_list)
custom_list); custom_list);
/* let other objects know about the new order */ /* let other objects know about the new order */
neworder = malloc (sizeof (gint) * custom_list->num_rows); neworder = g_new (gint, custom_list->num_rows);
for (i = custom_list->num_rows - 1; i >= 0; i--) for (i = custom_list->num_rows - 1; i >= 0; i--)
{ {
@ -744,7 +744,7 @@ custom_list_resort (CustomList * custom_list)
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (custom_list), path, NULL, gtk_tree_model_rows_reordered (GTK_TREE_MODEL (custom_list), path, NULL,
neworder); neworder);
gtk_tree_path_free (path); gtk_tree_path_free (path);
free (neworder); g_free (neworder);
} }
void void

View File

@ -130,25 +130,25 @@ dcc_send_filereq_file (struct my_dcc_send *mdc, char *file)
dcc_send (mdc->sess, mdc->nick, file, mdc->maxcps, mdc->passive); dcc_send (mdc->sess, mdc->nick, file, mdc->maxcps, mdc->passive);
else else
{ {
free (mdc->nick); g_free (mdc->nick);
free (mdc); g_free (mdc);
} }
} }
void void
fe_dcc_send_filereq (struct session *sess, char *nick, int maxcps, int passive) fe_dcc_send_filereq (struct session *sess, char *nick, int maxcps, int passive)
{ {
char tbuf[128]; char* tbuf = g_strdup_printf (_("Send file to %s"), nick);
struct my_dcc_send *mdc;
mdc = malloc (sizeof (*mdc)); struct my_dcc_send *mdc = g_new (struct my_dcc_send, 1);
mdc->sess = sess; mdc->sess = sess;
mdc->nick = strdup (nick); mdc->nick = g_strdup (nick);
mdc->maxcps = maxcps; mdc->maxcps = maxcps;
mdc->passive = passive; mdc->passive = passive;
snprintf (tbuf, sizeof tbuf, _("Send file to %s"), nick);
gtkutil_file_req (tbuf, dcc_send_filereq_file, mdc, prefs.hex_dcc_dir, NULL, FRF_MULTIPLE|FRF_FILTERISINITIAL); gtkutil_file_req (tbuf, dcc_send_filereq_file, mdc, prefs.hex_dcc_dir, NULL, FRF_MULTIPLE|FRF_FILTERISINITIAL);
g_free (tbuf);
} }
static void static void

View File

@ -224,7 +224,7 @@ fe_args (int argc, char *argv[])
/* cuts can. So we have to set the current dir manually, to the path */ /* cuts can. So we have to set the current dir manually, to the path */
/* of the exe. */ /* of the exe. */
{ {
char *tmp = strdup (argv[0]); char *tmp = g_strdup (argv[0]);
char *sl; char *sl;
sl = strrchr (tmp, G_DIR_SEPARATOR); sl = strrchr (tmp, G_DIR_SEPARATOR);
@ -233,7 +233,7 @@ fe_args (int argc, char *argv[])
*sl = 0; *sl = 0;
chdir (tmp); chdir (tmp);
} }
free (tmp); g_free (tmp);
} }
#endif #endif
@ -424,8 +424,7 @@ fe_new_window (session *sess, int focus)
void void
fe_new_server (struct server *serv) fe_new_server (struct server *serv)
{ {
serv->gui = malloc (sizeof (struct server_gui)); serv->gui = g_new0 (struct server_gui, 1);
memset (serv->gui, 0, sizeof (struct server_gui));
} }
void void
@ -510,18 +509,15 @@ fe_set_topic (session *sess, char *topic, char *stripped_topic)
} }
else else
{ {
if (sess->res->topic_text) g_free (sess->res->topic_text);
{
free (sess->res->topic_text);
}
if (prefs.hex_text_stripcolor_topic) if (prefs.hex_text_stripcolor_topic)
{ {
sess->res->topic_text = strdup (stripped_topic); sess->res->topic_text = g_strdup (stripped_topic);
} }
else else
{ {
sess->res->topic_text = strdup (topic); sess->res->topic_text = g_strdup (topic);
} }
} }
} }
@ -547,9 +543,8 @@ fe_update_mode_entry (session *sess, GtkWidget *entry, char **text, char *new_te
{ {
if (sess->gui->is_tab) if (sess->gui->is_tab)
{ {
if (*text) g_free (*text);
free (*text); *text = g_strdup (new_text);
*text = strdup (new_text);
} }
} }
} }
@ -721,7 +716,7 @@ fe_lastlog (session *sess, session *lastlog_sess, char *sstr, gtk_xtext_search_f
lbuf->search_lnee = strlen (lbuf->search_nee); lbuf->search_lnee = strlen (lbuf->search_nee);
} }
lbuf->search_flags = flags; lbuf->search_flags = flags;
lbuf->search_text = strdup (sstr); lbuf->search_text = g_strdup (sstr);
gtk_xtext_lastlog (lbuf, buf); gtk_xtext_lastlog (lbuf, buf);
} }
@ -761,9 +756,8 @@ fe_set_lag (server *serv, long lag)
sess = list->data; sess = list->data;
if (sess->server == serv) if (sess->server == serv)
{ {
if (sess->res->lag_tip) g_free (sess->res->lag_tip);
free (sess->res->lag_tip); sess->res->lag_tip = g_strdup (lagtip);
sess->res->lag_tip = strdup (lagtip);
if (!sess->gui->is_tab || current_tab == sess) if (!sess->gui->is_tab || current_tab == sess)
{ {
@ -777,9 +771,8 @@ fe_set_lag (server *serv, long lag)
} else } else
{ {
sess->res->lag_value = per; sess->res->lag_value = per;
if (sess->res->lag_text) g_free (sess->res->lag_text);
free (sess->res->lag_text); sess->res->lag_text = g_strdup (lagtext);
sess->res->lag_text = strdup (lagtext);
} }
} }
list = list->next; list = list->next;
@ -807,9 +800,8 @@ fe_set_throttle (server *serv)
snprintf (tbuf, sizeof (tbuf) - 1, _("%d bytes"), serv->sendq_len); snprintf (tbuf, sizeof (tbuf) - 1, _("%d bytes"), serv->sendq_len);
snprintf (tip, sizeof (tip) - 1, _("Network send queue: %d bytes"), serv->sendq_len); snprintf (tip, sizeof (tip) - 1, _("Network send queue: %d bytes"), serv->sendq_len);
if (sess->res->queue_tip) g_free (sess->res->queue_tip);
free (sess->res->queue_tip); sess->res->queue_tip = g_strdup (tip);
sess->res->queue_tip = strdup (tip);
if (!sess->gui->is_tab || current_tab == sess) if (!sess->gui->is_tab || current_tab == sess)
{ {
@ -823,9 +815,8 @@ fe_set_throttle (server *serv)
} else } else
{ {
sess->res->queue_value = per; sess->res->queue_value = per;
if (sess->res->queue_text) g_free (sess->res->queue_text);
free (sess->res->queue_text); sess->res->queue_text = g_strdup (tbuf);
sess->res->queue_text = strdup (tbuf);
} }
} }
list = list->next; list = list->next;
@ -977,9 +968,8 @@ fe_set_inputbox_contents (session *sess, char *text)
SPELL_ENTRY_SET_TEXT (sess->gui->input_box, text); SPELL_ENTRY_SET_TEXT (sess->gui->input_box, text);
} else } else
{ {
if (sess->res->input_text) g_free (sess->res->input_text);
free (sess->res->input_text); sess->res->input_text = g_strdup (text);
sess->res->input_text = strdup (text);
} }
} }

View File

@ -565,7 +565,7 @@ key_dialog_save (GtkWidget *wid, gpointer userdata)
{ {
do do
{ {
kb = (struct key_binding *) g_malloc0 (sizeof (struct key_binding)); kb = g_new0 (struct key_binding, 1);
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ACCEL_COLUMN, &accel, gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ACCEL_COLUMN, &accel,
ACTION_COLUMN, &actiontext, ACTION_COLUMN, &actiontext,
@ -945,7 +945,7 @@ key_load_kbs (void)
fd = hexchat_open_file ("keybindings.conf", O_RDONLY, 0, 0); fd = hexchat_open_file ("keybindings.conf", O_RDONLY, 0, 0);
if (fd < 0) if (fd < 0)
{ {
ibuf = strdup (default_kb_cfg); ibuf = g_strdup (default_kb_cfg);
size = strlen (default_kb_cfg); size = strlen (default_kb_cfg);
} }
else else
@ -956,7 +956,7 @@ key_load_kbs (void)
return 1; return 1;
} }
ibuf = malloc (st.st_size); ibuf = g_malloc(st.st_size);
read (fd, ibuf, st.st_size); read (fd, ibuf, st.st_size);
size = st.st_size; size = st.st_size;
close (fd); close (fd);
@ -978,7 +978,7 @@ key_load_kbs (void)
switch (state) switch (state)
{ {
case KBSTATE_MOD: case KBSTATE_MOD:
kb = (struct key_binding *) g_malloc0 (sizeof (struct key_binding)); kb = g_new0 (struct key_binding, 1);
/* New format */ /* New format */
if (strncmp (buf, "ACCEL=", 6) == 0) if (strncmp (buf, "ACCEL=", 6) == 0)
@ -1009,7 +1009,7 @@ key_load_kbs (void)
keyval = gdk_keyval_from_name (buf); keyval = gdk_keyval_from_name (buf);
if (keyval == 0) if (keyval == 0)
{ {
free (ibuf); g_free (ibuf);
return 2; return 2;
} }
@ -1025,7 +1025,7 @@ key_load_kbs (void)
if (kb->action == KEY_MAX_ACTIONS + 1) if (kb->action == KEY_MAX_ACTIONS + 1)
{ {
free (ibuf); g_free (ibuf);
return 3; return 3;
} }
@ -1042,7 +1042,7 @@ key_load_kbs (void)
if (buf[0] != 'D') if (buf[0] != 'D')
{ {
free (ibuf); g_free (ibuf);
return 4; return 4;
} }
@ -1068,12 +1068,10 @@ key_load_kbs (void)
len -= 3; len -= 3;
if (state == KBSTATE_DT1) if (state == KBSTATE_DT1)
{ {
kb->data1 = g_malloc (len); kb->data1 = g_strndup (&buf[3], len);
memcpy (kb->data1, &buf[3], len);
} else } else
{ {
kb->data2 = g_malloc (len); kb->data2 = g_strndup (&buf[3], len);
memcpy (kb->data2, &buf[3], len);
} }
} else if (buf[2] == '!') } else if (buf[2] == '!')
{ {
@ -1096,12 +1094,12 @@ key_load_kbs (void)
continue; continue;
} }
} }
free (ibuf); g_free (ibuf);
return 0; return 0;
corrupt_file: corrupt_file:
free (ibuf); g_free (ibuf);
free (kb); g_free (kb);
return 5; return 5;
} }

View File

@ -62,7 +62,7 @@ static void
gtkutil_file_req_destroy (GtkWidget * wid, struct file_req *freq) gtkutil_file_req_destroy (GtkWidget * wid, struct file_req *freq)
{ {
freq->callback (freq->userdata, NULL); freq->callback (freq->userdata, NULL);
free (freq); g_free (freq);
} }
static void static void
@ -255,7 +255,7 @@ gtkutil_file_req (const char *title, void *callback, void *userdata, char *filte
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), get_xdir (), NULL); gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), get_xdir (), NULL);
freq = malloc (sizeof (struct file_req)); freq = g_new (struct file_req, 1);
freq->dialog = dialog; freq->dialog = dialog;
freq->flags = flags; freq->flags = flags;
freq->callback = callback; freq->callback = callback;

View File

@ -312,7 +312,7 @@ mg_inputbox_cb (GtkWidget *igad, session_gui *gui)
if (cmd[0] == 0) if (cmd[0] == 0)
return; return;
cmd = strdup (cmd); cmd = g_strdup (cmd);
/* avoid recursive loop */ /* avoid recursive loop */
ignore = TRUE; ignore = TRUE;
@ -340,7 +340,7 @@ mg_inputbox_cb (GtkWidget *igad, session_gui *gui)
if (sess) if (sess)
handle_multiline (sess, cmd, TRUE, FALSE); handle_multiline (sess, cmd, TRUE, FALSE);
free (cmd); g_free (cmd);
} }
static gboolean static gboolean
@ -609,14 +609,14 @@ mg_unpopulate (session *sess)
gui = sess->gui; gui = sess->gui;
res = sess->res; res = sess->res;
res->input_text = strdup (SPELL_ENTRY_GET_TEXT (gui->input_box)); res->input_text = g_strdup (SPELL_ENTRY_GET_TEXT (gui->input_box));
res->topic_text = strdup (gtk_entry_get_text (GTK_ENTRY (gui->topic_entry))); res->topic_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (gui->topic_entry)));
res->limit_text = strdup (gtk_entry_get_text (GTK_ENTRY (gui->limit_entry))); res->limit_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (gui->limit_entry)));
res->key_text = strdup (gtk_entry_get_text (GTK_ENTRY (gui->key_entry))); res->key_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (gui->key_entry)));
if (gui->laginfo) if (gui->laginfo)
res->lag_text = strdup (gtk_label_get_text (GTK_LABEL (gui->laginfo))); res->lag_text = g_strdup (gtk_label_get_text (GTK_LABEL (gui->laginfo)));
if (gui->throttleinfo) if (gui->throttleinfo)
res->queue_text = strdup (gtk_label_get_text (GTK_LABEL (gui->throttleinfo))); res->queue_text = g_strdup (gtk_label_get_text (GTK_LABEL (gui->throttleinfo)));
for (i = 0; i < NUM_FLAG_WIDS - 1; i++) for (i = 0; i < NUM_FLAG_WIDS - 1; i++)
res->flag_wid_state[i] = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gui->flag_wid[i])); res->flag_wid_state[i] = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gui->flag_wid[i]));
@ -645,7 +645,7 @@ mg_restore_label (GtkWidget *label, char **text)
if (*text) if (*text)
{ {
gtk_label_set_text (GTK_LABEL (label), *text); gtk_label_set_text (GTK_LABEL (label), *text);
free (*text); g_free (*text);
*text = NULL; *text = NULL;
} else } else
{ {
@ -659,7 +659,7 @@ mg_restore_entry (GtkWidget *entry, char **text)
if (*text) if (*text)
{ {
gtk_entry_set_text (GTK_ENTRY (entry), *text); gtk_entry_set_text (GTK_ENTRY (entry), *text);
free (*text); g_free (*text);
*text = NULL; *text = NULL;
} else } else
{ {
@ -674,7 +674,7 @@ mg_restore_speller (GtkWidget *entry, char **text)
if (*text) if (*text)
{ {
SPELL_ENTRY_SET_TEXT (entry, *text); SPELL_ENTRY_SET_TEXT (entry, *text);
free (*text); g_free (*text);
*text = NULL; *text = NULL;
} else } else
{ {
@ -1331,8 +1331,7 @@ mg_close_gen (chan *ch, GtkWidget *box)
{ {
char *title = g_object_get_data (G_OBJECT (box), "title"); char *title = g_object_get_data (G_OBJECT (box), "title");
if (title) g_free (title);
free (title);
if (!ch) if (!ch)
ch = g_object_get_data (G_OBJECT (box), "ch"); ch = g_object_get_data (G_OBJECT (box), "ch");
if (ch) if (ch)
@ -1640,7 +1639,7 @@ mg_dnd_drop_file (session *sess, char *target, char *uri)
{ {
char *p, *data, *next, *fname; char *p, *data, *next, *fname;
p = data = strdup (uri); p = data = g_strdup (uri);
while (*p) while (*p)
{ {
next = strchr (p, '\r'); next = strchr (p, '\r');
@ -1667,7 +1666,7 @@ mg_dnd_drop_file (session *sess, char *target, char *uri)
if (*p == '\n') if (*p == '\n')
p++; p++;
} }
free (data); g_free (data);
} }
@ -1837,7 +1836,7 @@ mg_changui_destroy (session *sess)
/* it fixes: Gdk-CRITICAL **: gdk_colormap_get_screen: */ /* it fixes: Gdk-CRITICAL **: gdk_colormap_get_screen: */
/* assertion `GDK_IS_COLORMAP (cmap)' failed */ /* assertion `GDK_IS_COLORMAP (cmap)' failed */
ret = sess->gui->window; ret = sess->gui->window;
free (sess->gui); g_free (sess->gui);
sess->gui = NULL; sess->gui = NULL;
} }
return ret; return ret;
@ -3332,7 +3331,7 @@ mg_add_generic_tab (char *name, char *title, void *family, GtkWidget *box)
ch = chanview_add (mg_gui->chanview, name, NULL, box, TRUE, TAG_UTIL, pix_tree_util); ch = chanview_add (mg_gui->chanview, name, NULL, box, TRUE, TAG_UTIL, pix_tree_util);
chan_set_color (ch, plain_list); chan_set_color (ch, plain_list);
/* FIXME: memory leak */ /* FIXME: memory leak */
g_object_set_data (G_OBJECT (box), "title", strdup (title)); g_object_set_data (G_OBJECT (box), "title", g_strdup (title));
g_object_set_data (G_OBJECT (box), "ch", ch); g_object_set_data (G_OBJECT (box), "ch", ch);
if (prefs.hex_gui_tab_newtofront) if (prefs.hex_gui_tab_newtofront)
@ -3395,7 +3394,7 @@ fe_clear_channel (session *sess)
{ {
if (sess->res->topic_text) if (sess->res->topic_text)
{ {
free (sess->res->topic_text); g_free (sess->res->topic_text);
sess->res->topic_text = NULL; sess->res->topic_text = NULL;
} }
} }
@ -3508,24 +3507,24 @@ mg_changui_new (session *sess, restore_gui *res, int tab, int focus)
session_gui *gui; session_gui *gui;
struct User *user = NULL; struct User *user = NULL;
if (!res) if (res == NULL)
{ {
res = malloc (sizeof (restore_gui)); res = g_new0 (restore_gui, 1);
memset (res, 0, sizeof (restore_gui));
} }
sess->res = res; sess->res = res;
if (!sess->server->front_session) if (sess->server->front_session == NULL)
{
sess->server->front_session = sess; sess->server->front_session = sess;
}
if (!is_channel (sess->server, sess->channel)) if (!is_channel (sess->server, sess->channel))
user = userlist_find_global (sess->server, sess->channel); user = userlist_find_global (sess->server, sess->channel);
if (!tab) if (!tab)
{ {
gui = malloc (sizeof (session_gui)); gui = g_new0 (session_gui, 1);
memset (gui, 0, sizeof (session_gui));
gui->is_tab = FALSE; gui->is_tab = FALSE;
sess->gui = gui; sess->gui = gui;
mg_create_topwindow (sess); mg_create_topwindow (sess);
@ -3631,8 +3630,8 @@ mg_set_title (GtkWidget *vbox, char *title) /* for non-irc tab/window only */
old = g_object_get_data (G_OBJECT (vbox), "title"); old = g_object_get_data (G_OBJECT (vbox), "title");
if (old) if (old)
{ {
g_object_set_data (G_OBJECT (vbox), "title", strdup (title)); g_object_set_data (G_OBJECT (vbox), "title", g_strdup (title));
free (old); g_free (old);
} else } else
{ {
gtk_window_set_title (GTK_WINDOW (vbox), title); gtk_window_set_title (GTK_WINDOW (vbox), title);
@ -3650,7 +3649,7 @@ fe_server_callback (server *serv)
if (serv->gui->rawlog_window) if (serv->gui->rawlog_window)
mg_close_gen (NULL, serv->gui->rawlog_window); mg_close_gen (NULL, serv->gui->rawlog_window);
free (serv->gui); g_free (serv->gui);
} }
/* called when a session is being killed */ /* called when a session is being killed */
@ -3661,34 +3660,21 @@ fe_session_callback (session *sess)
if (sess->res->banlist && sess->res->banlist->window) if (sess->res->banlist && sess->res->banlist->window)
mg_close_gen (NULL, sess->res->banlist->window); mg_close_gen (NULL, sess->res->banlist->window);
if (sess->res->input_text) g_free (sess->res->input_text);
free (sess->res->input_text); g_free (sess->res->topic_text);
g_free (sess->res->limit_text);
if (sess->res->topic_text) g_free (sess->res->key_text);
free (sess->res->topic_text); g_free (sess->res->queue_text);
g_free (sess->res->queue_tip);
if (sess->res->limit_text) g_free (sess->res->lag_text);
free (sess->res->limit_text); g_free (sess->res->lag_tip);
if (sess->res->key_text)
free (sess->res->key_text);
if (sess->res->queue_text)
free (sess->res->queue_text);
if (sess->res->queue_tip)
free (sess->res->queue_tip);
if (sess->res->lag_text)
free (sess->res->lag_text);
if (sess->res->lag_tip)
free (sess->res->lag_tip);
if (sess->gui->bartag) if (sess->gui->bartag)
fe_timeout_remove (sess->gui->bartag); fe_timeout_remove (sess->gui->bartag);
if (sess->gui != &static_mg_gui) if (sess->gui != &static_mg_gui)
free (sess->gui); g_free (sess->gui);
free (sess->res); g_free (sess->res);
} }
/* ===== DRAG AND DROP STUFF ===== */ /* ===== DRAG AND DROP STUFF ===== */

View File

@ -137,7 +137,7 @@ nick_command_parse (session *sess, char *cmd, char *nick, char *allnick)
/* this can't overflow, since popup->cmd is only 256 */ /* this can't overflow, since popup->cmd is only 256 */
len = strlen (cmd) + strlen (nick) + strlen (allnick) + 512; len = strlen (cmd) + strlen (nick) + strlen (allnick) + 512;
buf = malloc (len); buf = g_malloc (len);
auto_insert (buf, len, cmd, 0, 0, allnick, sess->channel, "", auto_insert (buf, len, cmd, 0, 0, allnick, sess->channel, "",
server_get_network (sess->server, TRUE), host, server_get_network (sess->server, TRUE), host,
@ -145,7 +145,7 @@ nick_command_parse (session *sess, char *cmd, char *nick, char *allnick)
nick_command (sess, buf); nick_command (sess, buf);
free (buf); g_free (buf);
} }
/* userlist button has been clicked */ /* userlist button has been clicked */
@ -166,11 +166,12 @@ userlist_button_cb (GtkWidget * button, char *cmd)
if (sess->type == SESS_DIALOG) if (sess->type == SESS_DIALOG)
{ {
/* fake a selection */ /* fake a selection */
nicks = malloc (sizeof (char *) * 2); nicks = g_new (char *, 2);
nicks[0] = g_strdup (sess->channel); nicks[0] = g_strdup (sess->channel);
nicks[1] = NULL; nicks[1] = NULL;
num_sel = 1; num_sel = 1;
} else }
else
{ {
/* find number of selected rows */ /* find number of selected rows */
nicks = userlist_selection_list (sess->gui->user_tree, &num_sel); nicks = userlist_selection_list (sess->gui->user_tree, &num_sel);
@ -178,14 +179,13 @@ userlist_button_cb (GtkWidget * button, char *cmd)
{ {
nick_command_parse (sess, cmd, "", ""); nick_command_parse (sess, cmd, "", "");
if (nicks) g_free (nicks);
free (nicks);
return; return;
} }
} }
/* create "allnicks" string */ /* create "allnicks" string */
allnicks = malloc (((NICKLEN + 1) * num_sel) + 1); allnicks = g_malloc (((NICKLEN + 1) * num_sel) + 1);
*allnicks = 0; *allnicks = 0;
i = 0; i = 0;
@ -218,8 +218,8 @@ userlist_button_cb (GtkWidget * button, char *cmd)
g_free (nicks[num_sel]); g_free (nicks[num_sel]);
} }
free (nicks); g_free (nicks);
free (allnicks); g_free (allnicks);
} }
/* a popup-menu-item has been selected */ /* a popup-menu-item has been selected */
@ -726,9 +726,8 @@ menu_nickmenu (session *sess, GdkEventButton *event, char *nick, int num_sel)
struct User *user; struct User *user;
GtkWidget *submenu, *menu = gtk_menu_new (); GtkWidget *submenu, *menu = gtk_menu_new ();
if (str_copy) g_free (str_copy);
free (str_copy); str_copy = g_strdup (nick);
str_copy = strdup (nick);
submenu_list = 0; /* first time through, might not be 0 */ submenu_list = 0; /* first time through, might not be 0 */
@ -946,20 +945,19 @@ menu_urlmenu (GdkEventButton *event, char *url)
GtkWidget *menu; GtkWidget *menu;
char *tmp, *chop; char *tmp, *chop;
if (str_copy) g_free (str_copy);
free (str_copy); str_copy = g_strdup (url);
str_copy = strdup (url);
menu = gtk_menu_new (); menu = gtk_menu_new ();
/* more than 51 chars? Chop it */ /* more than 51 chars? Chop it */
if (g_utf8_strlen (str_copy, -1) >= 52) if (g_utf8_strlen (str_copy, -1) >= 52)
{ {
tmp = strdup (str_copy); tmp = g_strdup (str_copy);
chop = g_utf8_offset_to_pointer (tmp, 48); chop = g_utf8_offset_to_pointer (tmp, 48);
chop[0] = chop[1] = chop[2] = '.'; chop[0] = chop[1] = chop[2] = '.';
chop[3] = 0; chop[3] = 0;
menu_quick_item (0, tmp, menu, XCMENU_SHADED, 0, 0); menu_quick_item (0, tmp, menu, XCMENU_SHADED, 0, 0);
free (tmp); g_free (tmp);
} else } else
{ {
menu_quick_item (0, str_copy, menu, XCMENU_SHADED, 0, 0); menu_quick_item (0, str_copy, menu, XCMENU_SHADED, 0, 0);
@ -1024,9 +1022,8 @@ menu_chanmenu (struct session *sess, GdkEventButton * event, char *chan)
if (find_channel (sess->server, chan)) if (find_channel (sess->server, chan))
is_joined = TRUE; is_joined = TRUE;
if (str_copy) g_free (str_copy);
free (str_copy); str_copy = g_strdup (chan);
str_copy = strdup (chan);
menu = gtk_menu_new (); menu = gtk_menu_new ();
@ -1072,9 +1069,8 @@ menu_addfavoritemenu (server *serv, GtkWidget *menu, char *channel, gboolean ist
if (channel != str_copy) if (channel != str_copy)
{ {
if (str_copy) g_free (str_copy);
free (str_copy); str_copy = g_strdup (channel);
str_copy = strdup (channel);
} }
if (istree) if (istree)

View File

@ -106,7 +106,7 @@ palette_alloc (GtkWidget * widget)
void void
palette_load (void) palette_load (void)
{ {
int i, j, l, fh; int i, j, fh;
char prefname[256]; char prefname[256];
struct stat st; struct stat st;
char *cfg; char *cfg;
@ -116,13 +116,8 @@ palette_load (void)
if (fh != -1) if (fh != -1)
{ {
fstat (fh, &st); fstat (fh, &st);
cfg = malloc (st.st_size + 1); cfg = g_malloc0 (st.st_size + 1);
if (cfg) read (fh, cfg, st.st_size);
{
cfg[0] = '\0';
l = read (fh, cfg, st.st_size);
if (l >= 0)
cfg[l] = '\0';
/* mIRC colors 0-31 are here */ /* mIRC colors 0-31 are here */
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
@ -143,8 +138,7 @@ palette_load (void)
colors[j].green = green; colors[j].green = green;
colors[j].blue = blue; colors[j].blue = blue;
} }
free (cfg); g_free (cfg);
}
close (fh); close (fh);
} }
} }

View File

@ -142,14 +142,14 @@ plugingui_load_cb (session *sess, char *file)
{ {
if (file) if (file)
{ {
char *buf = malloc (strlen (file) + 9); char *buf;
if (strchr (file, ' ')) if (strchr (file, ' '))
sprintf (buf, "LOAD \"%s\"", file); buf = g_strdup_printf ("LOAD \"%s\"", file);
else else
sprintf (buf, "LOAD %s", file); buf = g_strdup_printf ("LOAD %s", file);
handle_command (sess, buf, FALSE); handle_command (sess, buf, FALSE);
free (buf); g_free (buf);
} }
} }
@ -173,7 +173,7 @@ plugingui_loadbutton_cb (GtkWidget * wid, gpointer unused)
static void static void
plugingui_unload (GtkWidget * wid, gpointer unused) plugingui_unload (GtkWidget * wid, gpointer unused)
{ {
char *modname, *file, *buf; char *modname, *file;
GtkTreeView *view; GtkTreeView *view;
GtkTreeIter iter; GtkTreeIter iter;
@ -186,16 +186,17 @@ plugingui_unload (GtkWidget * wid, gpointer unused)
{ {
if (plugin_kill (modname, FALSE) == 2) if (plugin_kill (modname, FALSE) == 2)
fe_message (_("That plugin is refusing to unload.\n"), FE_MSG_ERROR); fe_message (_("That plugin is refusing to unload.\n"), FE_MSG_ERROR);
} else }
{
/* let python.so or perl.so handle it */
buf = malloc (strlen (file) + 10);
if (strchr (file, ' '))
sprintf (buf, "UNLOAD \"%s\"", file);
else else
sprintf (buf, "UNLOAD %s", file); {
char *buf;
/* let python.so or perl.so handle it */
if (strchr (file, ' '))
buf = g_strdup_printf ("UNLOAD \"%s\"", file);
else
buf = g_strdup_printf ("UNLOAD %s", file);
handle_command (current_sess, buf, FALSE); handle_command (current_sess, buf, FALSE);
free (buf); g_free (buf);
} }
g_free (modname); g_free (modname);
@ -209,14 +210,14 @@ plugingui_reloadbutton_cb (GtkWidget *wid, GtkTreeView *view)
if (file) if (file)
{ {
char *buf = malloc (strlen (file) + 9); char *buf;
if (strchr (file, ' ')) if (strchr (file, ' '))
sprintf (buf, "RELOAD \"%s\"", file); buf = g_strdup_printf ("RELOAD \"%s\"", file);
else else
sprintf (buf, "RELOAD %s", file); buf = g_strdup_printf ("RELOAD %s", file);
handle_command (current_sess, buf, FALSE); handle_command (current_sess, buf, FALSE);
free (buf); g_free (buf);
g_free (file); g_free (file);
} }
} }

View File

@ -497,7 +497,7 @@ servlist_addnet_cb (GtkWidget *item, GtkTreeView *treeview)
ircnet *net; ircnet *net;
net = servlist_net_add (_("New Network"), "", TRUE); net = servlist_net_add (_("New Network"), "", TRUE);
net->encoding = strdup (IRC_DEFAULT_CHARSET); net->encoding = g_strdup (IRC_DEFAULT_CHARSET);
servlist_server_add (net, "newserver/6667"); servlist_server_add (net, "newserver/6667");
store = (GtkListStore *)gtk_tree_view_get_model (treeview); store = (GtkListStore *)gtk_tree_view_get_model (treeview);
@ -668,13 +668,12 @@ servlist_favor (GtkWidget *button, gpointer none)
static void static void
servlist_update_from_entry (char **str, GtkWidget *entry) servlist_update_from_entry (char **str, GtkWidget *entry)
{ {
if (*str) g_free (*str);
free (*str);
if (gtk_entry_get_text (GTK_ENTRY (entry))[0] == 0) if (gtk_entry_get_text (GTK_ENTRY (entry))[0] == 0)
*str = NULL; *str = NULL;
else else
*str = strdup (gtk_entry_get_text (GTK_ENTRY (entry))); *str = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
} }
static void static void
@ -1203,9 +1202,9 @@ servlist_celledit_cb (GtkCellRendererText *cell, gchar *arg1, gchar *arg2,
} }
netname = net->name; netname = net->name;
net->name = strdup (arg2); net->name = g_strdup (arg2);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, net->name, -1); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, net->name, -1);
free (netname); g_free (netname);
} }
gtk_tree_path_free (path); gtk_tree_path_free (path);
@ -1311,7 +1310,7 @@ servlist_sanitize_hostname (char *host)
{ {
char *ret, *c, *e; char *ret, *c, *e;
ret = strdup (host); ret = g_strdup (host);
c = strchr (ret, ':'); c = strchr (ret, ':');
e = strrchr (ret, ':'); e = strrchr (ret, ':');
@ -1371,7 +1370,7 @@ servlist_editserver_cb (GtkCellRendererText *cell, gchar *name, gchar *newval, g
servname = serv->hostname; servname = serv->hostname;
serv->hostname = servlist_sanitize_hostname (newval); serv->hostname = servlist_sanitize_hostname (newval);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, serv->hostname, -1); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, serv->hostname, -1);
free (servname); g_free (servname);
} }
} }
@ -1409,7 +1408,7 @@ servlist_editcommand_cb (GtkCellRendererText *cell, gchar *name, gchar *newval,
cmd = entry->command; cmd = entry->command;
entry->command = servlist_sanitize_command (newval); entry->command = servlist_sanitize_command (newval);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, entry->command, -1); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, entry->command, -1);
free (cmd); g_free (cmd);
} }
} }
@ -1508,9 +1507,8 @@ servlist_combo_cb (GtkEntry *entry, gpointer userdata)
if (!selected_net) if (!selected_net)
return; return;
if (selected_net->encoding) g_free (selected_net->encoding);
free (selected_net->encoding); selected_net->encoding = g_strdup (gtk_entry_get_text (entry));
selected_net->encoding = strdup (gtk_entry_get_text (entry));
} }
/* Fills up the network's authentication type so that it's guaranteed to be either NULL or a valid value. */ /* Fills up the network's authentication type so that it's guaranteed to be either NULL or a valid value. */

View File

@ -1684,9 +1684,8 @@ setup_snd_changed_cb (GtkEntry *ent, GtkTreeView *tree)
return; return;
/* get the new sound file */ /* get the new sound file */
if (sound_files[n]) g_free (sound_files[n]);
free (sound_files[n]); sound_files[n] = g_strdup (gtk_entry_get_text (GTK_ENTRY (ent)));
sound_files[n] = strdup (gtk_entry_get_text (GTK_ENTRY (ent)));
/* update the TreeView list */ /* update the TreeView list */
store = (GtkListStore *)gtk_tree_view_get_model (tree); store = (GtkListStore *)gtk_tree_view_get_model (tree);

View File

@ -292,7 +292,7 @@ insert_hiddenchar (SexySpellEntry *entry, guint start, guint end)
* is 'hidden' */ * is 'hidden' */
#if 0 #if 0
PangoAttribute *hattr; PangoAttribute *hattr;
PangoRectangle *rect = g_malloc (sizeof (PangoRectangle)); PangoRectangle *rect = g_new (PangoRectangle, 1);
rect->x = 0; rect->x = 0;
rect->y = 0; rect->y = 0;

View File

@ -81,12 +81,12 @@ PrintTextLine (xtext_buffer *xtbuf, unsigned char *text, int len, int indent, ti
timet = time (0); timet = time (0);
stamp_size = get_stamp_str (prefs.hex_stamp_text_format, timet, &stamp); stamp_size = get_stamp_str (prefs.hex_stamp_text_format, timet, &stamp);
new_text = malloc (len + stamp_size + 1); new_text = g_malloc (len + stamp_size + 1);
memcpy (new_text, stamp, stamp_size); memcpy (new_text, stamp, stamp_size);
g_free (stamp); g_free (stamp);
memcpy (new_text + stamp_size, text, len); memcpy (new_text + stamp_size, text, len);
gtk_xtext_append (xtbuf, new_text, len + stamp_size, timet); gtk_xtext_append (xtbuf, new_text, len + stamp_size, timet);
free (new_text); g_free (new_text);
} else } else
gtk_xtext_append (xtbuf, text, len, timet); gtk_xtext_append (xtbuf, text, len, timet);
return; return;
@ -173,13 +173,12 @@ pevent_edited (GtkCellRendererText *render, gchar *pathstr, gchar *new_text, gpo
} }
if (m > (te[sig].num_args & 0x7f)) if (m > (te[sig].num_args & 0x7f))
{ {
free (out); g_free (out);
out = malloc (4096); out = g_strdup_printf (
snprintf (out, 4096,
_("This signal is only passed %d args, $%d is invalid"), _("This signal is only passed %d args, $%d is invalid"),
te[sig].num_args & 0x7f, m); te[sig].num_args & 0x7f, m);
fe_message (out, FE_MSG_WARN); fe_message (out, FE_MSG_WARN);
free (out); g_free (out);
return; return;
} }
@ -188,23 +187,20 @@ pevent_edited (GtkCellRendererText *render, gchar *pathstr, gchar *new_text, gpo
gtk_list_store_set (GTK_LIST_STORE (model), &iter, TEXT_COLUMN, new_text, -1); gtk_list_store_set (GTK_LIST_STORE (model), &iter, TEXT_COLUMN, new_text, -1);
gtk_tree_path_free (path); gtk_tree_path_free (path);
if (pntevts_text[sig]) g_free (pntevts_text[sig]);
free (pntevts_text[sig]); g_free (pntevts[sig]);
if (pntevts[sig])
free (pntevts[sig]);
pntevts_text[sig] = malloc (len + 1); pntevts_text[sig] = g_strdup (text);
memcpy (pntevts_text[sig], text, len + 1);
pntevts[sig] = out; pntevts[sig] = out;
out = malloc (len + 2); out = g_malloc (len + 2);
memcpy (out, text, len + 1); memcpy (out, text, len + 1);
out[len] = '\n'; out[len] = '\n';
out[len + 1] = 0; out[len + 1] = 0;
check_special_chars (out, TRUE); check_special_chars (out, TRUE);
PrintTextRaw (xtext->buffer, out, 0, 0); PrintTextRaw (xtext->buffer, out, 0, 0);
free (out); g_free (out);
/* Scroll to bottom */ /* Scroll to bottom */
gtk_adjustment_set_value (xtext->adj, gtk_adjustment_get_upper (xtext->adj)); gtk_adjustment_set_value (xtext->adj, gtk_adjustment_get_upper (xtext->adj));
@ -328,14 +324,14 @@ pevent_test_cb (GtkWidget * wid, GtkWidget * twid)
text = _(pntevts_text[n]); text = _(pntevts_text[n]);
len = strlen (text); len = strlen (text);
out = malloc (len + 2); out = g_malloc (len + 2);
memcpy (out, text, len + 1); memcpy (out, text, len + 1);
out[len] = '\n'; out[len] = '\n';
out[len + 1] = 0; out[len + 1] = 0;
check_special_chars (out, TRUE); check_special_chars (out, TRUE);
PrintTextRaw (GTK_XTEXT (twid)->buffer, out, 0, 0); PrintTextRaw (GTK_XTEXT (twid)->buffer, out, 0, 0);
free (out); g_free (out);
} }
} }

View File

@ -188,7 +188,7 @@ userlist_selection_list (GtkWidget *widget, int *num_ret)
if (num_sel < 1) if (num_sel < 1)
return NULL; return NULL;
nicks = malloc (sizeof (char *) * (num_sel + 1)); nicks = g_new (char *, num_sel + 1);
i = 0; i = 0;
gtk_tree_model_get_iter_first (model, &iter); gtk_tree_model_get_iter_first (model, &iter);
@ -348,9 +348,9 @@ fe_userlist_insert (session *sess, struct User *newuser, int row, int sel)
nick = newuser->nick; nick = newuser->nick;
if (!prefs.hex_gui_ulist_icons) if (!prefs.hex_gui_ulist_icons)
{ {
nick = malloc (strlen (newuser->nick) + 2); nick = g_malloc (strlen (newuser->nick) + 2);
nick[0] = newuser->prefix[0]; nick[0] = newuser->prefix[0];
if (!nick[0] || nick[0] == ' ') if (nick[0] == '\0' || nick[0] == ' ')
strcpy (nick, newuser->nick); strcpy (nick, newuser->nick);
else else
strcpy (nick + 1, newuser->nick); strcpy (nick + 1, newuser->nick);
@ -367,7 +367,7 @@ fe_userlist_insert (session *sess, struct User *newuser, int row, int sel)
if (!prefs.hex_gui_ulist_icons) if (!prefs.hex_gui_ulist_icons)
{ {
free (nick); g_free (nick);
} }
/* is it me? */ /* is it me? */
@ -525,7 +525,7 @@ userlist_click_cb (GtkWidget *widget, GdkEventButton *event, gpointer userdata)
i--; i--;
g_free (nicks[i]); g_free (nicks[i]);
} }
free (nicks); g_free (nicks);
} }
return TRUE; return TRUE;
} }
@ -542,13 +542,13 @@ userlist_click_cb (GtkWidget *widget, GdkEventButton *event, gpointer userdata)
i--; i--;
g_free (nicks[i]); g_free (nicks[i]);
} }
free (nicks); g_free (nicks);
return TRUE; return TRUE;
} }
if (nicks) if (nicks)
{ {
g_free (nicks[0]); g_free (nicks[0]);
free (nicks); g_free (nicks);
} }
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)); sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
@ -567,7 +567,7 @@ userlist_click_cb (GtkWidget *widget, GdkEventButton *event, gpointer userdata)
i--; i--;
g_free (nicks[i]); g_free (nicks[i]);
} }
free (nicks); g_free (nicks);
} }
} else } else
{ {

View File

@ -1711,7 +1711,7 @@ gtk_xtext_get_word_adjust (GtkXText *xtext, int x, int y, textentry **word_ent,
} }
} }
} }
g_slist_free_full (slp, free); g_slist_free_full (slp, g_free);
return word_type; return word_type;
} }
@ -1857,7 +1857,7 @@ gtk_xtext_set_clip_owner (GtkWidget * xtext, GdkEventButton * event)
gtk_selection_owner_set (xtext, GDK_SELECTION_SECONDARY, event ? event->time : GDK_CURRENT_TIME); gtk_selection_owner_set (xtext, GDK_SELECTION_SECONDARY, event ? event->time : GDK_CURRENT_TIME);
} }
free (str); g_free (str);
} }
} }
@ -2111,7 +2111,7 @@ gtk_xtext_selection_get_text (GtkXText *xtext, int *len_ret)
return NULL; return NULL;
/* now allocate mem and copy buffer */ /* now allocate mem and copy buffer */
pos = txt = malloc (len); pos = txt = g_malloc (len);
ent = buf->last_ent_start; ent = buf->last_ent_start;
while (ent) while (ent)
{ {
@ -2151,10 +2151,11 @@ gtk_xtext_selection_get_text (GtkXText *xtext, int *len_ret)
/*stripped = gtk_xtext_conv_color (txt, strlen (txt), &len);*/ /*stripped = gtk_xtext_conv_color (txt, strlen (txt), &len);*/
stripped = txt; stripped = txt;
len = strlen (txt); len = strlen (txt);
} else }
else
{ {
stripped = gtk_xtext_strip_color (txt, strlen (txt), NULL, &len, NULL, FALSE); stripped = gtk_xtext_strip_color (txt, strlen (txt), NULL, &len, NULL, FALSE);
free (txt); g_free (txt);
} }
*len_ret = len; *len_ret = len;
@ -2209,7 +2210,7 @@ gtk_xtext_selection_get (GtkWidget * widget,
g_free (new_text); g_free (new_text);
} }
free (stripped); g_free (stripped);
} }
static gboolean static gboolean
@ -2364,7 +2365,7 @@ xtext_do_chunk(chunk_t *c)
if (c->len1 == 0) if (c->len1 == 0)
return; return;
meta = malloc (sizeof *meta); meta = g_new (offlen_t, 1);
meta->off = c->off1; meta->off = c->off1;
meta->len = c->len1; meta->len = c->len1;
meta->emph = c->emph; meta->emph = c->emph;
@ -2387,7 +2388,7 @@ gtk_xtext_strip_color (unsigned char *text, int len, unsigned char *outbuf,
int mbl; /* multi-byte length */ int mbl; /* multi-byte length */
if (outbuf == NULL) if (outbuf == NULL)
new_str = malloc (len + 2); new_str = g_malloc (len + 2);
else else
new_str = outbuf; new_str = outbuf;
@ -2463,7 +2464,7 @@ bad_utf8: /* Normal ending sequence, and give up if bad utf8 */
if (slpp) if (slpp)
*slpp = c.slp; *slpp = c.slp;
else else
g_slist_free_full (c.slp, free); g_slist_free_full (c.slp, g_free);
return new_str; return new_str;
} }
@ -2479,7 +2480,7 @@ gtk_xtext_text_width_ent (GtkXText *xtext, textentry *ent)
if (ent->slp) if (ent->slp)
{ {
g_slist_free_full (ent->slp, free); g_slist_free_full (ent->slp, g_free);
ent->slp = NULL; ent->slp = NULL;
} }
@ -2511,7 +2512,7 @@ gtk_xtext_text_width (GtkXText *xtext, unsigned char *text, int len)
&new_len, &slp, !xtext->ignore_hidden); &new_len, &slp, !xtext->ignore_hidden);
width = backend_get_text_width_slp (xtext, new_buf, slp); width = backend_get_text_width_slp (xtext, new_buf, slp);
g_slist_free_full (slp, free); g_slist_free_full (slp, g_free);
return width; return width;
} }
@ -3534,7 +3535,7 @@ gtk_xtext_save (GtkXText * xtext, int fh)
&newlen, NULL, FALSE); &newlen, NULL, FALSE);
write (fh, buf, newlen); write (fh, buf, newlen);
write (fh, "\n", 1); write (fh, "\n", 1);
free (buf); g_free (buf);
ent = ent->next; ent = ent->next;
} }
} }
@ -3899,10 +3900,10 @@ gtk_xtext_kill_ent (xtext_buffer *buffer, textentry *ent)
gtk_xtext_search_textentry_del (buffer, ent); gtk_xtext_search_textentry_del (buffer, ent);
} }
g_slist_free_full (ent->slp, free); g_slist_free_full (ent->slp, g_free);
g_slist_free (ent->sublines); g_slist_free (ent->sublines);
free (ent); g_free (ent);
return visible; return visible;
} }
@ -4037,7 +4038,7 @@ gtk_xtext_clear (xtext_buffer *buf, int lines)
while (buf->text_first) while (buf->text_first)
{ {
next = buf->text_first->next; next = buf->text_first->next;
free (buf->text_first); g_free (buf->text_first);
buf->text_first = next; buf->text_first = next;
} }
buf->text_last = NULL; buf->text_last = NULL;
@ -4214,7 +4215,7 @@ gtk_xtext_search_textentry (xtext_buffer *buf, textentry *ent)
} }
/* Common processing --- */ /* Common processing --- */
g_slist_free_full (slp, free); g_slist_free_full (slp, g_free);
return gl; return gl;
} }
@ -4643,7 +4644,7 @@ gtk_xtext_append_indent (xtext_buffer *buf,
if (right_text[right_len-1] == '\n') if (right_text[right_len-1] == '\n')
right_len--; right_len--;
ent = malloc (left_len + right_len + 2 + sizeof (textentry)); ent = g_malloc (left_len + right_len + 2 + sizeof (textentry));
str = (unsigned char *) ent + sizeof (textentry); str = (unsigned char *) ent + sizeof (textentry);
memcpy (str, left_text, left_len); memcpy (str, left_text, left_len);
@ -4698,7 +4699,7 @@ gtk_xtext_append (xtext_buffer *buf, unsigned char *text, int len, time_t stamp)
if (len >= sizeof (buf->xtext->scratch_buffer)) if (len >= sizeof (buf->xtext->scratch_buffer))
len = sizeof (buf->xtext->scratch_buffer) - 1; len = sizeof (buf->xtext->scratch_buffer) - 1;
ent = malloc (len + 1 + sizeof (textentry)); ent = g_malloc (len + 1 + sizeof (textentry));
ent->str = (unsigned char *) ent + sizeof (textentry); ent->str = (unsigned char *) ent + sizeof (textentry);
ent->str_len = len; ent->str_len = len;
if (len) if (len)
@ -4963,8 +4964,7 @@ gtk_xtext_buffer_new (GtkXText *xtext)
{ {
xtext_buffer *buf; xtext_buffer *buf;
buf = malloc (sizeof (xtext_buffer)); buf = g_new0 (xtext_buffer, 1);
memset (buf, 0, sizeof (xtext_buffer));
buf->old_value = -1; buf->old_value = -1;
buf->xtext = xtext; buf->xtext = xtext;
buf->scrollbar_down = TRUE; buf->scrollbar_down = TRUE;
@ -4994,9 +4994,9 @@ gtk_xtext_buffer_free (xtext_buffer *buf)
while (ent) while (ent)
{ {
next = ent->next; next = ent->next;
free (ent); g_free (ent);
ent = next; ent = next;
} }
free (buf); g_free (buf);
} }

View File

@ -78,7 +78,6 @@ fe_new_window (struct session *sess, int focus)
{ {
char buf[512]; char buf[512];
sess->gui = malloc (4);
current_sess = sess; current_sess = sess;
if (!sess->server->front_session) if (!sess->server->front_session)
@ -151,7 +150,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
char num[8]; char num[8];
int reverse = 0, under = 0, bold = 0, int reverse = 0, under = 0, bold = 0,
comma, k, i = 0, j = 0, len = strlen (text); comma, k, i = 0, j = 0, len = strlen (text);
unsigned char *newtext = malloc (len + 1024); unsigned char *newtext = g_malloc (len + 1024);
if (prefs.hex_stamp_text) if (prefs.hex_stamp_text)
{ {
@ -308,7 +307,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
newtext[j] = 0; newtext[j] = 0;
write (STDOUT_FILENO, newtext, j); write (STDOUT_FILENO, newtext, j);
free (newtext); g_free (newtext);
} }
#else #else
/* The win32 version for cmd.exe */ /* The win32 version for cmd.exe */
@ -319,7 +318,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
int dotime = FALSE; int dotime = FALSE;
int comma, k, i = 0, j = 0, len = strlen (text); int comma, k, i = 0, j = 0, len = strlen (text);
unsigned char *newtext = malloc (len + 1024); unsigned char *newtext = g_malloc (len + 1024);
if (prefs.hex_stamp_text) if (prefs.hex_stamp_text)
{ {
@ -403,7 +402,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
newtext[j] = 0; newtext[j] = 0;
write (STDOUT_FILENO, newtext, j); write (STDOUT_FILENO, newtext, j);
free (newtext); g_free (newtext);
} }
#endif #endif
@ -508,14 +507,14 @@ fe_args (int argc, char *argv[])
{ {
#ifdef WIN32 #ifdef WIN32
/* see the chdir() below */ /* see the chdir() below */
char *sl, *exe = strdup (argv[0]); char *sl, *exe = g_strdup (argv[0]);
sl = strrchr (exe, '\\'); sl = strrchr (exe, '\\');
if (sl) if (sl)
{ {
*sl = 0; *sl = 0;
printf ("%s\\plugins\n", exe); printf ("%s\\plugins\n", exe);
} }
free (exe); g_free (exe);
#else #else
printf ("%s\n", HEXCHATLIBDIR); printf ("%s\n", HEXCHATLIBDIR);
#endif #endif
@ -582,7 +581,6 @@ fe_exit (void)
void void
fe_new_server (struct server *serv) fe_new_server (struct server *serv)
{ {
serv->gui = malloc (4);
} }
void void