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;
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->cmd = pop->name + name_len;
@ -133,13 +133,13 @@ list_loadconf (char *file, GSList ** list, char *defaultconf)
abort ();
}
ibuf = malloc (st.st_size);
ibuf = g_malloc (st.st_size);
read (fd, ibuf, st.st_size);
close (fd);
list_load_from_data (list, ibuf, st.st_size);
free (ibuf);
g_free (ibuf);
}
void
@ -149,7 +149,7 @@ list_free (GSList ** list)
while (*list)
{
data = (void *) (*list)->data;
free (data);
g_free (data);
*list = g_slist_remove (*list, data);
}
}
@ -166,7 +166,7 @@ list_delentry (GSList ** list, char *name)
if (!g_ascii_strcasecmp (name, pop->name))
{
*list = g_slist_remove (*list, pop);
free (pop);
g_free (pop);
return 1;
}
alist = alist->next;
@ -647,7 +647,7 @@ get_default_language (void)
if (lang_no >= 0)
{
free (lang);
g_free (lang);
return lang_no;
}
@ -656,7 +656,7 @@ get_default_language (void)
lang_no = find_language_number (lang);
free (lang);
g_free (lang);
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)
{
/* 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);
/* 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);
}
free (prev_string);
g_free (prev_string);
}
else
{

View File

@ -208,7 +208,7 @@ chanopt_find (char *network, char *channel, gboolean add_new)
return NULL;
/* allocate a new one */
co = g_malloc0 (sizeof (chanopt_in_memory));
co = g_new0 (chanopt_in_memory, 1);
co->channel = g_strdup (channel);
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 */
conf = strdup (conf);
conf = g_strdup (conf);
/* process %C %B etc */
check_special_chars (conf, TRUE);
auto_insert (tbuf, sizeof (tbuf), conf, word, word_eol, "", "", word_eol[5],
server_get_network (sess->server, TRUE), "", "", nick, "");
free (conf);
g_free (conf);
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);
return TRUE;
}
free (cache_host);
g_free (cache_host);
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 (&cache_addr, h->h_addr, 4);
cache_host = strdup (host);
cache_host = g_strdup (host);
/* cppcheck-suppress memleak */
return TRUE;
}
@ -406,7 +406,7 @@ dcc_close (struct DCC *dcc, int dccstat, int destroy)
dcc->dccstat = dccstat;
if (dcc->dccchat)
{
free (dcc->dccchat);
g_free (dcc->dccchat);
dcc->dccchat = NULL;
}
@ -417,7 +417,7 @@ dcc_close (struct DCC *dcc, int dccstat, int destroy)
g_free (dcc->proxy);
g_free (dcc->file);
g_free (dcc->destfile);
free (dcc->nick);
g_free (dcc->nick);
g_free (dcc);
return;
}
@ -888,8 +888,7 @@ dcc_connect_finished (GIOChannel *source, GIOCondition condition, struct DCC *dc
dcc_open_query (dcc->serv, dcc->nick);
case TYPE_CHATRECV: /* normal chat */
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
dcc->dccchat = malloc (sizeof (struct dcc_chat));
dcc->dccchat->pos = 0;
dcc->dccchat = g_new0 (struct dcc_chat, 1);
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
dcc->nick, host, NULL, NULL, 0);
break;
@ -1369,12 +1368,6 @@ dcc_proxy_connect (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
return TRUE;
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)
{
@ -1463,9 +1456,7 @@ dcc_send_data (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
else if (!dcc->wiotag)
dcc->wiotag = fe_input_add (sok, FIA_WRITE, dcc_send_data, dcc);
buf = malloc (prefs.hex_dcc_blocksize);
if (!buf)
return TRUE;
buf = g_malloc (prefs.hex_dcc_blocksize);
lseek (dcc->fp, dcc->pos, SEEK_SET);
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 ()))
{
abortit:
free (buf);
g_free (buf);
EMIT_SIGNAL (XP_TE_DCCSENDFAIL, dcc->serv->front_session,
file_part (dcc->file), dcc->nick,
errorstring (sock_error ()), NULL, 0);
@ -1500,7 +1491,7 @@ abortit:
}
}
free (buf);
g_free (buf);
return TRUE;
}
@ -1630,8 +1621,7 @@ dcc_accept (GIOChannel *source, GIOCondition condition, struct DCC *dcc)
case TYPE_CHATSEND:
dcc_open_query (dcc->serv, dcc->nick);
dcc->iotag = fe_input_add (dcc->sok, FIA_READ|FIA_EX, dcc_read_chat, dcc);
dcc->dccchat = malloc (sizeof (struct dcc_chat));
dcc->dccchat->pos = 0;
dcc->dccchat = g_new0 (struct dcc_chat, 1);
EMIT_SIGNAL (XP_TE_DCCCONCHAT, dcc->serv->front_session,
dcc->nick, host, NULL, NULL, 0);
break;
@ -1897,7 +1887,7 @@ dcc_send (struct session *sess, char *to, char *filename, gint64 maxcps, int pas
}
filename++;
}
dcc->nick = strdup (to);
dcc->nick = g_strdup (to);
if (prefs.hex_gui_autoopen_send)
{
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 (dcc->nick)
free (dcc->nick);
dcc->nick = strdup (newnick);
g_free (dcc->nick);
dcc->nick = g_strdup (newnick);
}
}
list = list->next;
@ -2257,11 +2246,6 @@ static struct DCC *
new_dcc (void)
{
struct DCC *dcc = g_new0 (struct DCC, 1);
if (!dcc)
{
return NULL;
}
dcc->sok = -1;
dcc->fp = -1;
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->dccstat = STAT_QUEUED;
dcc->type = TYPE_CHATSEND;
dcc->nick = strdup (nick);
dcc->nick = g_strdup (nick);
if (passive || dcc_listen_init (dcc, sess))
{
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->port = port;
dcc->pasvid = pasvid;
dcc->nick = strdup (nick);
dcc->nick = g_strdup (nick);
dcc->starttime = time (0);
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->pasvid = pasvid;
dcc->size = size;
dcc->nick = strdup (nick);
dcc->nick = g_strdup (nick);
dcc->maxcps = prefs.hex_dcc_max_get_cps;
update_is_resumable (dcc);

View File

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

View File

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

View File

@ -42,7 +42,7 @@ identd (char *username)
sok = socket (AF_INET, SOCK_STREAM, 0);
if (sok == INVALID_SOCKET)
{
free (username);
g_free (username);
return 0;
}
@ -56,14 +56,14 @@ identd (char *username)
if (bind (sok, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
{
closesocket (sok);
free (username);
g_free (username);
return 0;
}
if (listen (sok, 1) == SOCKET_ERROR)
{
closesocket (sok);
free (username);
g_free (username);
return 0;
}
@ -72,7 +72,7 @@ identd (char *username)
closesocket (sok);
if (read_sok == INVALID_SOCKET)
{
free (username);
g_free (username);
return 0;
}
@ -99,7 +99,7 @@ identd (char *username)
sleep (1);
closesocket (read_sok);
free (username);
g_free (username);
return 0;
}
@ -118,7 +118,7 @@ identd_ipv6 (char *username)
sok = socket (AF_INET6, SOCK_STREAM, 0);
if (sok == INVALID_SOCKET)
{
free (username);
g_free (username);
return 0;
}
@ -132,14 +132,14 @@ identd_ipv6 (char *username)
if (bind (sok, (struct sockaddr *) &addr, sizeof (addr)) == SOCKET_ERROR)
{
closesocket (sok);
free (username);
g_free (username);
return 0;
}
if (listen (sok, 1) == SOCKET_ERROR)
{
closesocket (sok);
free (username);
g_free (username);
return 0;
}
@ -148,7 +148,7 @@ identd_ipv6 (char *username)
closesocket (sok);
if (read_sok == INVALID_SOCKET)
{
free (username);
g_free (username);
return 0;
}
@ -171,7 +171,7 @@ identd_ipv6 (char *username)
sleep (1);
closesocket (read_sok);
free (username);
g_free (username);
return 0;
}
@ -188,7 +188,7 @@ identd_start (char *username)
{
identd_ipv6_is_running = TRUE;
CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) identd_ipv6,
strdup (username), 0, &tidv6));
g_strdup (username), 0, &tidv6));
}
#endif
@ -196,6 +196,6 @@ identd_start (char *username)
{
identd_is_running = TRUE;
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 *
ignore_exists (char *mask)
{
struct ignore *ig = 0;
struct ignore *ig = NULL;
GSList *list;
list = ignore_list;
@ -79,7 +79,7 @@ ignore_exists (char *mask)
int
ignore_add (char *mask, int type, gboolean overwrite)
{
struct ignore *ig = 0;
struct ignore *ig = NULL;
int change_only = FALSE;
/* first check if it's already ignored */
@ -88,12 +88,9 @@ ignore_add (char *mask, int type, gboolean overwrite)
change_only = TRUE;
if (!change_only)
ig = malloc (sizeof (struct ignore));
ig = g_new (struct ignore, 1);
if (!ig)
return 0;
ig->mask = strdup (mask);
ig->mask = g_strdup (mask);
if (!overwrite && change_only)
ig->type |= type;
@ -192,8 +189,8 @@ ignore_del (char *mask, struct ignore *ig)
if (ig)
{
ignore_list = g_slist_remove (ignore_list, ig);
free (ig->mask);
free (ig);
g_free (ig->mask);
g_free (ig);
fe_ignore_update (1);
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));
if (!my_cfg)
return NULL;
ignore->mask = strdup (tbuf);
ignore->mask = g_strdup (tbuf);
}
if (my_cfg)
{
@ -281,7 +278,7 @@ ignore_load ()
struct ignore *ignore;
struct stat st;
char *cfg, *my_cfg;
int fh, i;
int fh;
fh = hexchat_open_file ("ignore.conf", O_RDONLY, 0, 0);
if (fh != -1)
@ -289,22 +286,18 @@ ignore_load ()
fstat (fh, &st);
if (st.st_size)
{
cfg = malloc (st.st_size + 1);
cfg[0] = '\0';
i = read (fh, cfg, st.st_size);
if (i >= 0)
cfg[i] = '\0';
cfg = g_malloc0 (st.st_size + 1);
read (fh, cfg, st.st_size);
my_cfg = cfg;
while (my_cfg)
{
ignore = malloc (sizeof (struct ignore));
memset (ignore, 0, sizeof (struct ignore));
ignore = g_new0 (struct ignore, 1);
if ((my_cfg = ignore_read_next_entry (my_cfg, ignore)))
ignore_list = g_slist_prepend (ignore_list, ignore);
else
free (ignore);
g_free (ignore);
}
free (cfg);
g_free (cfg);
}
close (fh);
}

View File

@ -62,7 +62,7 @@ clear_channel (session *sess)
if (sess->current_modes)
{
free (sess->current_modes);
g_free (sess->current_modes);
sess->current_modes = NULL;
}
@ -81,9 +81,8 @@ clear_channel (session *sess)
void
set_topic (session *sess, char *topic, char *stripped_topic)
{
if (sess->topic)
free (sess->topic);
sess->topic = strdup (stripped_topic);
g_free (sess->topic);
sess->topic = g_strdup (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- */
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, ']');
if (end)
{
*end = 0;
sess = find_channel (serv, dest);
}
free (dest);
g_free (dest);
}
}
if (!sess)
@ -1454,8 +1453,7 @@ inbound_user_info (session *sess, char *chan, char *user, char *host,
if (user && host)
{
uhost = g_malloc (strlen (user) + strlen (host) + 2);
sprintf (uhost, "%s@%s", user, host);
uhost = g_strdup_printf ("%s@%s", user, host);
}
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_insert(current, argument_offset+1, arg);
free(sess->current_modes);
g_free(sess->current_modes);
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);
}
free(sess->current_modes);
g_free(sess->current_modes);
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 */
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);
}
}
@ -374,12 +374,13 @@ mode_cat (char *str, char *addition)
if (str)
{
len = strlen (str) + strlen (addition) + 2;
str = realloc (str, len);
str = g_realloc (str, len);
strcat (str, " ");
strcat (str, addition);
} else
}
else
{
str = strdup (addition);
str = g_strdup (addition);
}
return str;
@ -560,12 +561,12 @@ handle_single_mode (mode_run *mr, char sign, char mode, char *nick,
{
if (*arg)
{
char *buf = malloc (strlen (chan) + strlen (arg) + 2);
sprintf (buf, "%s %s", chan, arg);
char *buf = g_strdup_printf ("%s %s", chan, arg);
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANMODEGEN, sess, nick, outbuf,
outbuf + 2, buf, 0, tags_data->timestamp);
free (buf);
} else
g_free (buf);
}
else
EMIT_SIGNAL_TIMESTAMP (XP_TE_CHANMODEGEN, sess, nick, outbuf,
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,
tags_data->timestamp);
free (mr->op);
g_free(mr->op);
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,
0, tags_data->timestamp);
free (mr->deop);
g_free(mr->deop);
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,
0, tags_data->timestamp);
free (mr->voice);
g_free(mr->voice);
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,
NULL, 0, tags_data->timestamp);
free (mr->devoice);
g_free(mr->devoice);
mr->devoice = NULL;
}
}
@ -717,9 +718,8 @@ handle_mode (server * serv, char *word[], char *word_eol[],
if (numeric_324 && !using_front_tab)
{
if (sess->current_modes)
free (sess->current_modes);
sess->current_modes = strdup (word_eol[offset+1]);
g_free (sess->current_modes);
sess->current_modes = g_strdup (word_eol[offset+1]);
}
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);
} else if (strncmp (word[w], "CHANTYPES=", 10) == 0)
{
free (serv->chantypes);
serv->chantypes = strdup (word[w] + 10);
g_free (serv->chantypes);
serv->chantypes = g_strdup (word[w] + 10);
} else if (strncmp (word[w], "CHANMODES=", 10) == 0)
{
free (serv->chanmodes);
serv->chanmodes = strdup (word[w] + 10);
g_free (serv->chanmodes);
serv->chanmodes = g_strdup (word[w] + 10);
} else if (strncmp (word[w], "PREFIX=", 7) == 0)
{
pre = strchr (word[w] + 7, ')');
if (pre)
{
pre[0] = 0; /* NULL out the ')' */
free (serv->nick_prefixes);
free (serv->nick_modes);
serv->nick_prefixes = strdup (pre + 1);
serv->nick_modes = strdup (word[w] + 8);
g_free (serv->nick_prefixes);
g_free (serv->nick_modes);
serv->nick_prefixes = g_strdup (pre + 1);
serv->nick_modes = g_strdup (word[w] + 8);
} else
{
/* bad! some ircds don't give us the modes. */
/* in this case, we use it only to strip /NAMES */
serv->bad_prefix = TRUE;
if (serv->bad_nick_prefixes)
free (serv->bad_nick_prefixes);
serv->bad_nick_prefixes = strdup (word[w] + 7);
g_free (serv->bad_nick_prefixes);
serv->bad_nick_prefixes = g_strdup (word[w] + 7);
}
} 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;
} 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)
{
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)
freeaddrinfo (ns->ip6_hostent);
#endif
free (ns);
g_free (ns);
}
netstore *
net_store_new (void)
{
netstore *ns;
ns = malloc (sizeof (netstore));
memset (ns, 0, sizeof (netstore));
return ns;
return g_new0 (netstore, 1);
}
#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_family = AF_INET;
*real_host = strdup (ns->ip4_hostent->h_name);
return strdup (inet_ntoa (ns->addr.sin_addr));
*real_host = g_strdup (ns->ip4_hostent->h_name);
return g_strdup (inet_ntoa (ns->addr.sin_addr));
}
int
@ -232,11 +227,11 @@ net_resolve (netstore * ns, char *hostname, int port, char **real_host)
ipstring, sizeof (ipstring), NULL, 0, NI_NUMERICHOST);
if (ns->ip6_hostent->ai_canonname)
*real_host = strdup (ns->ip6_hostent->ai_canonname);
*real_host = g_strdup (ns->ip6_hostent->ai_canonname);
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 */
@ -310,15 +305,15 @@ net_store_fill_any (netstore *ns)
struct sockaddr_in *sin;
ai = ns->ip6_hostent;
if (!ai) {
ai = malloc (sizeof (struct addrinfo));
memset (ai, 0, sizeof (struct addrinfo));
if (ai == NULL)
{
ai = g_new0 (struct addrinfo, 1);
ns->ip6_hostent = ai;
}
sin = (struct sockaddr_in *)ai->ai_addr;
if (!sin) {
sin = malloc (sizeof (struct sockaddr_in));
memset (sin, 0, sizeof (struct sockaddr_in));
if (sin == NULL)
{
sin = g_new0 (struct sockaddr_in, 1);
ai->ai_addr = (struct sockaddr *)sin;
}
ai->ai_family = AF_INET;
@ -336,15 +331,15 @@ net_store_fill_v4 (netstore *ns, guint32 addr, int port)
struct sockaddr_in *sin;
ai = ns->ip6_hostent;
if (!ai) {
ai = malloc (sizeof (struct addrinfo));
memset (ai, 0, sizeof (struct addrinfo));
if (ai == NULL)
{
ai = g_new0 (struct addrinfo, 1);
ns->ip6_hostent = ai;
}
sin = (struct sockaddr_in *)ai->ai_addr;
if (!sin) {
sin = malloc (sizeof (struct sockaddr_in));
memset (sin, 0, sizeof (struct sockaddr_in));
if (sin == NULL)
{
sin = g_new0 (struct sockaddr_in, 1);
ai->ai_addr = (struct sockaddr *)sin;
}
ai->ai_family = AF_INET;

View File

@ -47,7 +47,7 @@ int notify_tag = 0;
static char *
despacify_dup (char *str)
{
char *p, *res = malloc (strlen (str) + 1);
char *p, *res = g_malloc (strlen (str) + 1);
p = res;
while (1)
@ -70,11 +70,11 @@ notify_netcmp (char *str, void *serv)
if (rfc_casecmp (str, net) == 0)
{
free (net);
g_free (net);
return 0; /* finish & return FALSE from token_foreach() */
}
free (net);
g_free (net);
return 1; /* keep going... */
}
@ -111,14 +111,10 @@ notify_find_server_entry (struct notify *notify, struct server *serv)
if (!notify_do_network (notify, serv))
return NULL;
servnot = malloc (sizeof (struct notify_per_server));
if (servnot)
{
memset (servnot, 0, sizeof (struct notify_per_server));
servnot->server = serv;
servnot->notify = notify;
notify->server_list = g_slist_prepend (notify->server_list, servnot);
}
servnot = g_new0 (struct notify_per_server, 1);
servnot->server = serv;
servnot->notify = notify;
notify->server_list = g_slist_prepend (notify->server_list, 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) */
char *wii_str = malloc (strlen (nick) * 2 + 2);
sprintf (wii_str, "%s %s", nick, nick);
char *wii_str = g_strdup_printf ("%s %s", nick, nick);
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;
notify->server_list =
g_slist_remove (notify->server_list, servnot);
free (servnot);
g_free (servnot);
}
notify_list = g_slist_remove (notify_list, notify);
notify_watch_all (notify, FALSE);
if (notify->networks)
free (notify->networks);
free (notify->name);
free (notify);
g_free (notify->networks);
g_free (notify->name);
g_free (notify);
fe_notify_update (0);
return 1;
}
@ -615,27 +609,18 @@ notify_deluser (char *name)
void
notify_adduser (char *name, char *networks)
{
struct notify *notify = malloc (sizeof (struct notify));
if (notify)
{
memset (notify, 0, sizeof (struct notify));
if (strlen (name) >= NICKLEN)
{
notify->name = malloc (NICKLEN);
safe_strcpy (notify->name, name, NICKLEN);
} else
{
notify->name = strdup (name);
}
if (networks)
notify->networks = despacify_dup (networks);
notify->server_list = 0;
notify_list = g_slist_prepend (notify_list, notify);
notify_checklist ();
fe_notify_update (notify->name);
fe_notify_update (0);
notify_watch_all (notify, TRUE);
}
struct notify *notify = g_new0 (struct notify, 1);
notify->name = g_strndup (name, NICKLEN - 1);
if (networks != NULL)
notify->networks = despacify_dup (networks);
notify->server_list = 0;
notify_list = g_slist_prepend (notify_list, notify);
notify_checklist ();
fe_notify_update (notify->name);
fe_notify_update (0);
notify_watch_all (notify, TRUE);
}
gboolean
@ -714,7 +699,7 @@ notify_cleanup ()
{
notify->server_list =
g_slist_remove (notify->server_list, servnot);
free (servnot);
g_free (servnot);
nslist = notify->server_list;
} else
{

View File

@ -90,7 +90,7 @@ random_line (char *file_name)
{
nofile:
/* reason is not a file, an actual reason! */
return strdup (file_name);
return g_strdup (file_name);
}
/* count number of lines in file */
@ -111,7 +111,7 @@ random_line (char *file_name)
}
while (lines > ran);
fclose (fh);
return strdup (buf);
return g_strdup (buf);
}
void
@ -121,7 +121,7 @@ server_sendpart (server * serv, char *channel, char *reason)
{
reason = random_line (prefs.hex_irc_part_reason);
serv->p_part (serv, channel, reason);
free (reason);
g_free (reason);
} else
{
/* reason set by /quit, /close argument */
@ -136,12 +136,12 @@ server_sendquit (session * sess)
if (!sess->quitreason)
{
colrea = strdup (prefs.hex_irc_quit_reason);
colrea = g_strdup (prefs.hex_irc_quit_reason);
check_special_chars (colrea, FALSE);
rea = random_line (colrea);
free (colrea);
g_free (colrea);
sess->server->p_quit (sess->server, rea);
free (rea);
g_free (rea);
} else
{
/* reason set by /quit, /close argument */
@ -269,7 +269,7 @@ cmd_addserver (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!network)
{
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 */
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)
free (sess->server->last_away_reason);
g_free (sess->server->last_away_reason);
if (reason == word_eol[2])
sess->server->last_away_reason = strdup (reason);
sess->server->last_away_reason = g_strdup (reason);
else
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"));
}
if (sess->server->last_away_reason)
free (sess->server->last_away_reason);
g_free (sess->server->last_away_reason);
sess->server->last_away_reason = NULL;
return TRUE;
@ -1002,14 +1000,14 @@ mdehop_cb (struct User *user, multidata *data)
static int
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;
data.nicks = nicks;
data.i = 0;
tree_foreach (sess->usertree, (tree_traverse_func *)mdehop_cb, &data);
send_channel_modes (sess, tbuf, nicks, 0, data.i, '-', 'h', 0);
free (nicks);
g_free (nicks);
return TRUE;
}
@ -1028,14 +1026,14 @@ mdeop_cb (struct User *user, multidata *data)
static int
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;
data.nicks = nicks;
data.i = 0;
tree_foreach (sess->usertree, (tree_traverse_func *)mdeop_cb, &data);
send_channel_modes (sess, tbuf, nicks, 0, data.i, '-', 'o', 0);
free (nicks);
g_free (nicks);
return TRUE;
}
@ -1045,18 +1043,13 @@ GSList *menu_list = NULL;
static void
menu_free (menu_entry *me)
{
free (me->path);
if (me->label)
free (me->label);
if (me->cmd)
free (me->cmd);
if (me->ucmd)
free (me->ucmd);
if (me->group)
free (me->group);
if (me->icon)
free (me->icon);
free (me);
g_free (me->path);
g_free (me->label);
g_free (me->cmd);
g_free (me->ucmd);
g_free (me->group);
g_free (me->icon);
g_free (me);
}
/* 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;
}
me = malloc (sizeof (menu_entry));
me = g_new (menu_entry, 1);
me->pos = pos;
me->modifier = mod;
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->enable = enable;
me->key = key;
me->path = strdup (path);
me->path = g_strdup (path);
me->label = NULL;
me->cmd = NULL;
me->ucmd = NULL;
me->group = NULL;
me->icon = NULL;
if (label)
me->label = strdup (label);
if (cmd)
me->cmd = strdup (cmd);
if (ucmd)
me->ucmd = strdup (ucmd);
if (group)
me->group = strdup (group);
if (icon)
me->icon = strdup (icon);
me->label = g_strdup (label);
me->cmd = g_strdup (cmd);
me->ucmd = g_strdup (ucmd);
me->group = g_strdup (group);
me->icon = g_strdup (icon);
menu_list = g_slist_append (menu_list, me);
label = fe_menu_add (me);
if (label)
{
/* FE has given us a stripped label */
free (me->label);
me->label = strdup (label);
g_free (me->label);
me->label = g_strdup (label);
g_free (label); /* this is from pango */
}
}
@ -1456,7 +1444,7 @@ exec_check_process (struct session *sess)
{
close (sess->running_exec->myfd);
fe_input_remove (sess->running_exec->iotag);
free (sess->running_exec);
g_free (sess->running_exec);
sess->running_exec = NULL;
}
}
@ -1533,11 +1521,10 @@ cmd_execw (struct session *sess, char *tbuf, char *word[], char *word_eol[])
return FALSE;
}
len = strlen(word_eol[2]);
temp = malloc(len + 2);
sprintf(temp, "%s\n", word_eol[2]);
temp = g_strconcat (word_eol[2], "\n", NULL);
PrintText(sess, temp);
write(sess->running_exec->myfd, temp, len + 1);
free(temp);
g_free(temp);
return TRUE;
}
@ -1561,7 +1548,7 @@ exec_handle_colors (char *buf, int len)
if (strchr (buf, 27) == 0)
return;
nbuf = malloc (len + 1);
nbuf = g_malloc (len + 1);
while (i < len)
{
@ -1655,7 +1642,7 @@ norm: nbuf[j] = buf[i];
nbuf[j] = 0;
memcpy (buf, nbuf, j + 1);
free (nbuf);
g_free (nbuf);
}
#ifndef HAVE_MEMRCHR
@ -1681,14 +1668,14 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
len = s->buffill;
if (len) {
/* append new data to buffered incomplete line */
buf = malloc(len + 2050);
buf = g_malloc (len + 2050);
memcpy(buf, s->linebuf, len);
readpos = buf + len;
free(s->linebuf);
g_free (s->linebuf);
s->linebuf = NULL;
}
else
readpos = buf = malloc(2050);
readpos = buf = g_malloc (2050);
rd = read (sok, readpos, 2048);
if (rd < 1)
@ -1709,12 +1696,12 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
else
PrintText (s->sess, buf);
}
free(buf);
g_free(buf);
waitpid (s->childpid, NULL, 0);
s->sess->running_exec = NULL;
fe_input_remove (s->iotag);
close (sok);
free (s);
g_free (s);
return TRUE;
}
len += rd;
@ -1727,7 +1714,7 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
rest = buf;
if (*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);
*rest = '\0';
len -= s->buffill; /* possibly 0 */
@ -1743,7 +1730,7 @@ exec_data (GIOChannel *source, GIOCondition condition, struct nbexec *s)
PrintText (s->sess, buf);
}
free(buf);
g_free (buf);
return TRUE;
}
@ -1805,8 +1792,7 @@ cmd_exec (struct session *sess, char *tbuf, char *word[], char *word_eol[])
return FALSE;
}
#endif
s = (struct nbexec *) malloc (sizeof (struct nbexec));
memset(s, 0, sizeof(*s));
s = g_new0 (struct nbexec, 1);
s->myfd = fds[0];
s->tochannel = tochannel;
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");
close(fds[0]);
close(fds[1]);
free (s);
} else
g_free (s);
}
else
{
/* Parent path */
close(fds[1]);
@ -1946,8 +1933,8 @@ get_bool_cb (int val, getvalinfo *info)
if (is_session (info->sess))
handle_command (info->sess, buf, FALSE);
free (info->cmd);
free (info);
g_free (info->cmd);
g_free (info);
}
static int
@ -1958,8 +1945,8 @@ cmd_getbool (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!word[4][0])
return FALSE;
info = malloc (sizeof (*info));
info->cmd = strdup (word[2]);
info = g_new (getvalinfo, 1);
info->cmd = g_strdup (word[2]);
info->sess = sess;
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);
}
free (info->cmd);
free (info);
g_free (info->cmd);
g_free (info);
}
static int
@ -1991,8 +1978,8 @@ cmd_getint (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!word[4][0])
return FALSE;
info = malloc (sizeof (*info));
info->cmd = strdup (word[3]);
info = g_new (getvalinfo, 1);
info->cmd = g_strdup (word[3]);
info->sess = sess;
fe_get_int (word[4], atoi (word[2]), get_int_cb, info);
@ -2015,7 +2002,7 @@ get_file_cb (char *cmd, char *file)
else
{
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++;
}
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;
}
@ -2063,8 +2050,8 @@ get_str_cb (int cancel, char *val, getvalinfo *info)
handle_command (info->sess, buf, FALSE);
}
free (info->cmd);
free (info);
g_free (info->cmd);
g_free (info);
}
static int
@ -2075,8 +2062,8 @@ cmd_getstr (struct session *sess, char *tbuf, char *word[], char *word_eol[])
if (!word[4][0])
return FALSE;
info = malloc (sizeof (*info));
info->cmd = strdup (word[3]);
info = g_new (getvalinfo, 1);
info->cmd = g_strdup (word[3]);
info->sess = sess;
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
{
struct popup *pop;
char *buf = malloc (4096);
char *buf = g_malloc (4096);
help_list hl;
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);
strcat (buf, "\n");
PrintText (sess, buf);
free (buf);
g_free (buf);
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
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;
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);
send_channel_modes (sess, tbuf, nicks, 0, data.i, '+', 'o', 0);
free (nicks);
g_free (nicks);
return TRUE;
}
@ -4313,81 +4300,78 @@ check_special_chars (char *cmd, int do_ascii) /* check for %X */
if (!len)
return;
buf = malloc (len + 1);
buf = g_malloc (len + 1);
if (buf)
while (cmd[j])
{
while (cmd[j])
switch (cmd[j])
{
switch (cmd[j])
case '%':
occur++;
if ( do_ascii &&
j + 3 < len &&
(isdigit ((unsigned char) cmd[j + 1]) && isdigit ((unsigned char) cmd[j + 2]) &&
isdigit ((unsigned char) cmd[j + 3])))
{
case '%':
occur++;
if ( do_ascii &&
j + 3 < len &&
(isdigit ((unsigned char) cmd[j + 1]) && isdigit ((unsigned char) cmd[j + 2]) &&
isdigit ((unsigned char) cmd[j + 3])))
tbuf[0] = cmd[j + 1];
tbuf[1] = cmd[j + 2];
tbuf[2] = cmd[j + 3];
tbuf[3] = 0;
buf[i] = atoi (tbuf);
utf = g_locale_to_utf8 (buf + i, 1, 0, &utf_len, 0);
if (utf)
{
tbuf[0] = cmd[j + 1];
tbuf[1] = cmd[j + 2];
tbuf[2] = cmd[j + 3];
tbuf[3] = 0;
buf[i] = atoi (tbuf);
utf = g_locale_to_utf8 (buf + i, 1, 0, &utf_len, 0);
if (utf)
{
memcpy (buf + i, utf, utf_len);
g_free (utf);
i += (utf_len - 1);
}
j += 3;
} else
{
switch (cmd[j + 1])
{
case 'R':
buf[i] = '\026';
break;
case 'U':
buf[i] = '\037';
break;
case 'B':
buf[i] = '\002';
break;
case 'I':
buf[i] = '\035';
break;
case 'C':
buf[i] = '\003';
break;
case 'O':
buf[i] = '\017';
break;
case 'H': /* CL: invisible text code */
buf[i] = HIDDEN_CHAR;
break;
case '%':
buf[i] = '%';
break;
default:
buf[i] = '%';
j--;
break;
}
j++;
break;
default:
buf[i] = cmd[j];
memcpy (buf + i, utf, utf_len);
g_free (utf);
i += (utf_len - 1);
}
j += 3;
} else
{
switch (cmd[j + 1])
{
case 'R':
buf[i] = '\026';
break;
case 'U':
buf[i] = '\037';
break;
case 'B':
buf[i] = '\002';
break;
case 'I':
buf[i] = '\035';
break;
case 'C':
buf[i] = '\003';
break;
case 'O':
buf[i] = '\017';
break;
case 'H': /* CL: invisible text code */
buf[i] = HIDDEN_CHAR;
break;
case '%':
buf[i] = '%';
break;
default:
buf[i] = '%';
j--;
break;
}
j++;
break;
default:
buf[i] = cmd[j];
}
j++;
i++;
}
buf[i] = 0;
if (occur)
strcpy (cmd, buf);
free (buf);
j++;
i++;
}
buf[i] = 0;
if (occur)
strcpy (cmd, buf);
g_free (buf);
}
typedef struct
@ -4487,12 +4471,10 @@ handle_say (session *sess, char *text, int check_spch)
struct DCC *dcc;
char *word[PDIWORDS+1];
char *word_eol[PDIWORDS+1];
char pdibuf_static[1024];
char newcmd_static[1024];
char *pdibuf = pdibuf_static;
char *newcmd = newcmd_static;
char *pdibuf;
char *newcmd;
int len;
int newcmdlen = sizeof newcmd_static;
int newcmdlen;
message_tags_data no_tags = MESSAGE_TAGS_DATA_INIT;
if (strcmp (sess->channel, "(lastlog)") == 0)
@ -4502,11 +4484,9 @@ handle_say (session *sess, char *text, int check_spch)
}
len = strlen (text);
if (len >= sizeof pdibuf_static)
pdibuf = malloc (len + 1);
if (len + NICKLEN >= newcmdlen)
newcmd = malloc (newcmdlen = len + NICKLEN + 1);
pdibuf = g_malloc (len + 1);
newcmdlen = MAX(len + NICKLEN + 1, TBUFSIZE);
newcmd = g_malloc (newcmdlen);
if (check_spch && prefs.hex_input_perc_color)
check_special_chars (text, prefs.hex_input_perc_ascii);
@ -4579,11 +4559,9 @@ handle_say (session *sess, char *text, int check_spch)
}
xit:
if (pdibuf != pdibuf_static)
free (pdibuf);
g_free (pdibuf);
if (newcmd != newcmd_static)
free (newcmd);
g_free (newcmd);
}
char *
@ -4677,8 +4655,6 @@ handle_command (session *sess, char *cmd, int check_spch)
char *word_eol[PDIWORDS+1];
static int command_level = 0;
struct commands *int_cmd;
char pdibuf_static[1024];
char tbuf_static[TBUFSIZE];
char *pdibuf;
char *tbuf;
int len;
@ -4693,23 +4669,8 @@ handle_command (session *sess, char *cmd, int check_spch)
/* anything below MUST DEC command_level before returning */
len = strlen (cmd);
if (len >= sizeof (pdibuf_static))
{
pdibuf = malloc (len + 1);
}
else
{
pdibuf = pdibuf_static;
}
if ((len * 2) >= sizeof (tbuf_static))
{
tbuf = malloc ((len * 2) + 1);
}
else
{
tbuf = tbuf_static;
}
pdibuf = g_malloc (len + 1);
tbuf = g_malloc (MAX(TBUFSIZE, (len * 2) + 1));
/* split the text into words and word_eol */
process_data_init (pdibuf, cmd, word, word_eol, TRUE, TRUE);
@ -4802,15 +4763,8 @@ handle_command (session *sess, char *cmd, int check_spch)
xit:
command_level--;
if (pdibuf != pdibuf_static)
{
free (pdibuf);
}
if (tbuf != tbuf_static)
{
free (tbuf);
}
g_free (pdibuf);
g_free (tbuf);
return ret;
}

View File

@ -53,9 +53,9 @@ static void
timer_del (timer *tim)
{
timer_list = g_slist_remove (timer_list, tim);
free (tim->command);
g_free (tim->command);
hexchat_unhook (ph, tim->hook);
free (tim);
g_free (tim);
}
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->repeat = repeat;
tim->timeout = timeout;
tim->command = strdup (command);
tim->command = g_strdup (command);
tim->context = hexchat_get_context (ph);
tim->forever = FALSE;

View File

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

View File

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

View File

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

View File

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

View File

@ -504,9 +504,7 @@ _SSL_check_common_name (X509 *cert, const char *host)
if (common_name_len < 0)
return -1;
common_name = calloc (common_name_len + 1, 1);
if (common_name == NULL)
return -1;
common_name = g_malloc0 (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;
out:
free(common_name);
g_free(common_name);
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);
else
buf = NULL;
free (chan);
g_free (chan);
return buf;
}
@ -406,7 +406,7 @@ log_create_filename (char *channame)
char *tmp, *ret;
int mbl;
ret = tmp = strdup (channame);
ret = tmp = g_strdup (channame);
while (*tmp)
{
mbl = g_utf8_skip[((unsigned char *)tmp)[0]];
@ -542,7 +542,7 @@ log_create_pathname (char *servname, char *channame, char *netname)
if (!netname)
{
netname = strdup ("NETWORK");
netname = g_strdup ("NETWORK");
}
else
{
@ -552,7 +552,7 @@ log_create_pathname (char *servname, char *channame, char *netname)
/* first, everything is in UTF-8 */
if (!rfc_casecmp (channame, servname))
{
channame = strdup ("server");
channame = g_strdup ("server");
}
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);
free (channame);
free (netname);
g_free (channame);
g_free (netname);
/* insert time/date */
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 */
res = output = g_malloc ((len * 3) + 1);
if (!output)
return NULL;
while (len)
{
@ -1565,14 +1563,13 @@ pevent_load_defaults ()
for (i = 0; i < NUM_XP; i++)
{
if (pntevts_text[i])
free (pntevts_text[i]);
g_free (pntevts_text[i]);
/* make-te.c sets this 128 flag (DON'T call gettext() flag) */
if (te[i].num_args & 128)
pntevts_text[i] = strdup (te[i].def);
pntevts_text[i] = g_strdup (te[i].def);
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++)
{
if (pntevts[i] != NULL)
free (pntevts[i]);
g_free (pntevts[i]);
if (pevt_build_string (pntevts_text[i], &(pntevts[i]), &m) != 0)
{
snprintf (out, sizeof (out),
_("Error parsing event %s.\nLoading default."), te[i].name);
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) */
if (te[i].num_args & 128)
pntevts_text[i] = strdup (te[i].def);
pntevts_text[i] = g_strdup (te[i].def);
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)
{
fprintf (stderr,
@ -1618,22 +1614,17 @@ pevent_make_pntevts ()
static void
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;
if (penum != -1 && text != NULL)
{
len = strlen (text) + 1;
if (pntevts_text[penum])
free (pntevts_text[penum]);
pntevts_text[penum] = malloc (len);
memcpy (pntevts_text[penum], text, len);
g_free (pntevts_text[penum]);
pntevts_text[penum] = g_strdup (text);
}
if (text)
free (text);
if (snd)
free (snd);
g_free (text);
g_free (snd);
*i_text = NULL;
*i_snd = NULL;
*i_penum = 0;
@ -1686,7 +1677,7 @@ pevent_load (char *filename)
close (fd);
return 1;
}
ibuf = malloc (st.st_size);
ibuf = g_malloc (st.st_size);
read (fd, ibuf, st.st_size);
close (fd);
@ -1702,8 +1693,6 @@ pevent_load (char *filename)
continue;
*ofs = 0;
ofs++;
/*if (*ofs == 0)
continue;*/
if (strcmp (buf, "event_name") == 0)
{
@ -1713,53 +1702,16 @@ pevent_load (char *filename)
continue;
} else if (strcmp (buf, "event_text") == 0)
{
if (text)
free (text);
#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
g_free (text);
text = g_strdup (ofs);
continue;
}/* else if (strcmp (buf, "event_sound") == 0)
{
if (snd)
free (snd);
snd = strdup (ofs);
continue;
}*/
}
continue;
}
pevent_trigger_load (&penum, &text, &snd);
free (ibuf);
g_free (ibuf);
return 0;
}
@ -1777,9 +1729,9 @@ pevent_check_all_loaded ()
gtkutil_simpledialog(out); */
/* make-te.c sets this 128 flag (DON'T call gettext() flag) */
if (te[i].num_args & 128)
pntevts_text[i] = strdup (te[i].def);
pntevts_text[i] = g_strdup (te[i].def);
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;
len = strlen (input);
i = malloc (len + 1);
i = g_malloc (len + 1);
memcpy (i, input, len + 1);
check_special_chars (i, TRUE);
@ -1921,14 +1873,14 @@ pevt_build_string (const char *input, char **output, int *max_arg)
}
if (oi > 0)
{
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1));
s = g_new (struct pevt_stage1, 1);
if (base == NULL)
base = s;
if (last != NULL)
last->next = s;
last = s;
s->next = NULL;
s->data = malloc (oi + sizeof (int) + 1);
s->data = g_malloc (oi + sizeof (int) + 1);
s->len = oi + sizeof (int) + 1;
clen += oi + sizeof (int) + 1;
s->data[0] = 0;
@ -1939,11 +1891,12 @@ pevt_build_string (const char *input, char **output, int *max_arg)
if (ii == len)
{
fe_message ("String ends with a $", FE_MSG_WARN);
return 1;
goto err;
}
d = i[ii++];
if (d == 'a')
{ /* Hex value */
{
/* Hex value */
x = 0;
if (ii == len)
goto a_len_error;
@ -1965,26 +1918,24 @@ pevt_build_string (const char *input, char **output, int *max_arg)
o[oi++] = x;
continue;
a_len_error:
a_len_error:
fe_message ("String ends in $a", FE_MSG_WARN);
free (i);
return 1;
a_range_error:
goto err;
a_range_error:
fe_message ("$a value is greater than 255", FE_MSG_WARN);
free (i);
return 1;
goto err;
}
if (d == 't')
{
/* 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)
base = s;
if (last != NULL)
last->next = s;
last = s;
s->next = NULL;
s->data = malloc (1);
s->data = g_malloc (1);
s->len = 1;
clen += 1;
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);
fe_message (o, FE_MSG_WARN);
free (i);
return 1;
goto err;
}
d -= '0';
if (max < d)
max = d;
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1));
s = g_new (struct pevt_stage1, 1);
if (base == NULL)
base = s;
if (last != NULL)
last->next = s;
last = s;
s->next = NULL;
s->data = malloc (2);
s->data = g_malloc (2);
s->len = 2;
clen += 2;
s->data[0] = 1;
@ -2016,14 +1966,14 @@ pevt_build_string (const char *input, char **output, int *max_arg)
}
if (oi > 0)
{
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1));
s = g_new (struct pevt_stage1, 1);
if (base == NULL)
base = s;
if (last != NULL)
last->next = s;
last = s;
s->next = NULL;
s->data = malloc (oi + sizeof (int) + 1);
s->data = g_malloc (oi + sizeof (int) + 1);
s->len = oi + sizeof (int) + 1;
clen += oi + sizeof (int) + 1;
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);
oi = 0;
}
s = (struct pevt_stage1 *) malloc (sizeof (struct pevt_stage1));
s = g_new (struct pevt_stage1, 1);
if (base == NULL)
base = s;
if (last != NULL)
last->next = s;
last = s;
s->next = NULL;
s->data = malloc (1);
s->data = g_malloc (1);
s->len = 1;
clen += 1;
s->data[0] = 2;
oi = 0;
s = base;
obuf = malloc (clen);
obuf = g_malloc (clen);
while (s)
{
next = s->next;
memcpy (&obuf[oi], s->data, s->len);
oi += s->len;
free (s->data);
free (s);
g_free (s->data);
g_free (s);
s = next;
}
free (i);
g_free (i);
if (max_arg)
*max_arg = max;
if (output)
*output = obuf;
else
free (obuf);
g_free (obuf);
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 (sound_files[i])
free (sound_files[i]);
sound_files[i] = strdup (file);
g_free (sound_files[i]);
sound_files[i] = g_strdup (file);
}
}

View File

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

View File

@ -20,6 +20,8 @@
#ifndef HEXCHAT_TREE_H
#define HEXCHAT_TREE_H
#include <glib.h>
typedef struct _tree tree;
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
url_free (char *url, void *data)
{
free (url);
g_free (url);
return TRUE;
}
@ -124,13 +124,7 @@ url_add (char *urltext, int len)
return;
}
data = malloc (len + 1);
if (!data)
{
return;
}
memcpy (data, urltext, len);
data[len] = 0;
data = g_strndup (urltext, len);
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 */
if (!prefs.hex_url_grabber)
{
free (data);
g_free (data);
return;
}
@ -163,7 +157,7 @@ url_add (char *urltext, int len)
if (url_find (data))
{
free (data);
g_free (data);
return;
}
@ -180,7 +174,7 @@ url_add (char *urltext, int len)
pos = tree_remove_at_pos (url_tree, 0);
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);
if (user)
{
if (user->account)
free (user->account);
g_free (user->account);
if (strcmp (account, "*") == 0)
user->account = NULL;
else
user->account = strdup (account);
user->account = g_strdup (account);
/* gui doesnt currently reflect login status, maybe later
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)
do_rehash = TRUE;
user->hostname = strdup (hostname);
user->hostname = g_strdup (hostname);
}
if (!user->realname && realname && *realname)
user->realname = strdup (realname);
user->realname = g_strdup (realname);
if (!user->servername && servername)
user->servername = strdup (servername);
user->servername = g_strdup (servername);
if (!user->account && account && strcmp (account, "0") != 0)
user->account = strdup (account);
user->account = g_strdup (account);
if (away != 0xff)
{
if (user->away != away)
@ -175,15 +174,11 @@ userlist_add_hostname (struct session *sess, char *nick, char *hostname,
static int
free_user (struct User *user, gpointer data)
{
if (user->realname)
free (user->realname);
if (user->hostname)
free (user->hostname);
if (user->servername)
free (user->servername);
if (user->account)
free (user->account);
free (user);
g_free (user->realname);
g_free (user->hostname);
g_free (user->servername);
g_free (user->account);
g_free (user);
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);
user = malloc (sizeof (struct User));
memset (user, 0, sizeof (struct User));
user = g_new0 (struct User, 1);
user->access = acc;
@ -408,7 +402,7 @@ userlist_add (struct session *sess, char *name, char *hostname,
/* add it to our linked list */
if (hostname)
user->hostname = strdup (hostname);
user->hostname = g_strdup (hostname);
safe_strcpy (user->nick, name + prefix_chars, NICKLEN);
/* is it me? */
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 (account && *account)
user->account = strdup (account);
user->account = g_strdup (account);
if (realname && *realname)
user->realname = strdup (realname);
user->realname = g_strdup (realname);
}
row = userlist_insertname (sess, user);
@ -427,13 +421,10 @@ userlist_add (struct session *sess, char *name, char *hostname,
/* duplicate? some broken servers trigger this */
if (row == -1)
{
if (user->hostname)
free (user->hostname);
if (user->account)
free (user->account);
if (user->realname)
free (user->realname);
free (user);
g_free (user->hostname);
g_free (user->account);
g_free (user->realname);
g_free (user);
return;
}

View File

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

View File

@ -198,13 +198,13 @@
* only defined for compatibility. These macros should always return false
* on Windows.
*/
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
/* Return the exact length of d_namlen without zero terminator */
#define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
@ -305,6 +305,7 @@ _wopendir(
{
_WDIR *dirp = NULL;
int error;
DWORD n;
/* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') {
@ -313,73 +314,58 @@ _wopendir(
}
/* Allocate new _WDIR structure */
dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
if (dirp != NULL) {
DWORD n;
dirp = (_WDIR*) g_new (struct _WDIR, 1);
/* Reset _WDIR structure */
dirp->handle = INVALID_HANDLE_VALUE;
dirp->patt = NULL;
dirp->cached = 0;
/* Reset _WDIR structure */
dirp->handle = INVALID_HANDLE_VALUE;
dirp->patt = NULL;
dirp->cached = 0;
/* Compute the length of full path plus zero terminator */
n = GetFullPathNameW (dirname, 0, NULL, NULL);
/* Compute the length of full path plus zero terminator */
n = GetFullPathNameW (dirname, 0, NULL, NULL);
/* Allocate room for absolute directory name and search pattern */
dirp->patt = g_malloc (sizeof (wchar_t) * n + 16);
/*
* Convert relative directory name to an absolute one. This
* allows rewinddir() to function correctly even when current
* working directory is changed between opendir() and rewinddir().
*/
n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
if (n > 0) {
wchar_t *p;
/* Allocate room for absolute directory name and search pattern */
dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
if (dirp->patt) {
/* Append search pattern \* to the directory name */
p = dirp->patt + n;
if (dirp->patt < p) {
switch (p[-1]) {
case '\\':
case '/':
case ':':
/* Directory ends in path separator, e.g. c:\temp\ */
/*NOP*/;
break;
/*
* Convert relative directory name to an absolute one. This
* allows rewinddir() to function correctly even when current
* working directory is changed between opendir() and rewinddir().
*/
n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
if (n > 0) {
wchar_t *p;
/* Append search pattern \* to the directory name */
p = dirp->patt + n;
if (dirp->patt < p) {
switch (p[-1]) {
case '\\':
case '/':
case ':':
/* Directory ends in path separator, e.g. c:\temp\ */
/*NOP*/;
break;
default:
/* Directory name doesn't end in path separator */
*p++ = '\\';
}
}
*p++ = '*';
*p = '\0';
/* Open directory stream and retrieve the first entry */
if (dirent_first (dirp)) {
/* Directory stream opened successfully */
error = 0;
} else {
/* Cannot retrieve first entry */
error = 1;
dirent_set_errno (ENOENT);
}
} else {
/* Cannot retrieve full path name */
dirent_set_errno (ENOENT);
error = 1;
default:
/* Directory name doesn't end in path separator */
*p++ = '\\';
}
}
*p++ = '*';
*p = '\0';
/* Open directory stream and retrieve the first entry */
if (dirent_first (dirp)) {
/* Directory stream opened successfully */
error = 0;
} else {
/* Cannot allocate memory for search pattern */
/* Cannot retrieve first entry */
error = 1;
dirent_set_errno (ENOENT);
}
} else {
/* Cannot allocate _WDIR structure */
/* Cannot retrieve full path name */
dirent_set_errno (ENOENT);
error = 1;
}
@ -472,13 +458,11 @@ _wclosedir(
}
/* Release search pattern */
if (dirp->patt) {
free (dirp->patt);
dirp->patt = NULL;
}
g_free (dirp->patt);
dirp->patt = NULL;
/* Release directory structure */
free (dirp);
g_free (dirp);
ok = /*success*/0;
} else {
@ -579,6 +563,8 @@ opendir(
{
struct DIR *dirp;
int error;
wchar_t wname[PATH_MAX + 1];
size_t n;
/* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') {
@ -587,44 +573,36 @@ opendir(
}
/* Allocate memory for DIR structure */
dirp = (DIR*) malloc (sizeof (struct DIR));
if (dirp) {
wchar_t wname[PATH_MAX + 1];
size_t n;
dirp = (DIR*) g_new (struct DIR, 1);
/* Convert directory name to wide-character string */
error = dirent_mbstowcs_s(
&n, wname, PATH_MAX + 1, dirname, PATH_MAX);
if (!error) {
/* Open directory stream using wide-character name */
dirp->wdirp = _wopendir (wname);
if (dirp->wdirp) {
/* Directory stream opened */
error = 0;
} else {
/* Failed to open directory stream */
error = 1;
}
/* Convert directory name to wide-character string */
error = dirent_mbstowcs_s(
&n, wname, PATH_MAX + 1, dirname, PATH_MAX);
if (!error) {
/* Open directory stream using wide-character name */
dirp->wdirp = _wopendir (wname);
if (dirp->wdirp) {
/* Directory stream opened */
error = 0;
} else {
/*
* Cannot convert file name to wide-character string. This
* occurs if the string contains invalid multi-byte sequences or
* the output buffer is too small to contain the resulting
* string.
*/
/* Failed to open directory stream */
error = 1;
}
} else {
/* Cannot allocate DIR structure */
/*
* Cannot convert file name to wide-character string. This
* occurs if the string contains invalid multi-byte sequences or
* the output buffer is too small to contain the resulting
* string.
*/
error = 1;
}
/* Clean up in case of error */
if (error && dirp) {
free (dirp);
if (error != 0) {
g_free (dirp);
dirp = NULL;
}
@ -733,14 +711,14 @@ closedir(
DIR *dirp)
{
int ok;
if (dirp) {
if (dirp != NULL) {
/* Close wide-character directory stream */
ok = _wclosedir (dirp->wdirp);
dirp->wdirp = NULL;
/* Release multi-byte character version */
free (dirp);
g_free (dirp);
} 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))
return 0;
masks = g_malloc (sizeof (char *) * banl->line_ct);
masks = g_new (char *, banl->line_ct);
num_sel = 0;
do
{
@ -577,17 +577,17 @@ static void
banlist_add_selected_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
{
GSList **lp = data;
GSList *list = NULL;
GtkTreeIter *copy;
if (!lp) return;
list = *lp;
copy = g_malloc (sizeof (GtkTreeIter));
g_return_if_fail (copy != NULL);
if (lp == NULL)
{
return;
}
copy = g_new (GtkTreeIter, 1);
*copy = *iter;
list = g_slist_append (list, copy);
*(GSList **)data = list;
*lp = g_slist_append (*lp, copy);
}
static void
@ -786,14 +786,9 @@ banlist_opengui (struct session *sess)
return;
}
if (!sess->res->banlist)
if (sess->res->banlist == NULL)
{
sess->res->banlist = g_malloc0 (sizeof (banlist_info));
if (!sess->res->banlist)
{
fe_message (_("Banlist initialization failed."), FE_MSG_ERROR);
return;
}
sess->res->banlist = g_new0 (banlist_info, 1);
}
banl = sess->res->banlist;
if (banl->window)

View File

@ -148,7 +148,7 @@ chanlist_data_free (server *serv)
data = rows->data;
g_free (data->topic);
g_free (data->collation_key);
free (data);
g_free (data);
}
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;
/* 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);
next_row->topic = strip_color (topic, -1, STRIP_ALL);
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)
{
/* truncate long channel names */
buf = malloc (strlen (name) + 4);
strcpy (buf, name);
g_utf8_offset_to_pointer (buf, max)[0] = 0;
buf = g_malloc (strlen (name) + 4);
g_utf8_strncpy (buf, name, max);
strcat (buf, "..");
return buf;
}
@ -231,7 +230,7 @@ chanview_free_ch (chanview *cv, GtkTreeIter *iter)
chan *ch;
gtk_tree_model_get (GTK_TREE_MODEL (cv->store), iter, COL_CHAN, &ch, -1);
free (ch);
g_free (ch);
}
static void
@ -251,7 +250,7 @@ chanview_destroy (chanview *cv)
gtk_widget_destroy (cv->box);
chanview_destroy_store (cv);
free (cv);
g_free (cv);
}
static void
@ -267,7 +266,7 @@ chanview_new (int type, int trunc_len, gboolean sort, gboolean use_icons,
{
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,
PANGO_TYPE_ATTR_LIST, GDK_TYPE_PIXBUF);
cv->style = style;
@ -368,7 +367,7 @@ chanview_add_real (chanview *cv, char *name, void *family, void *userdata,
if (!ch)
{
ch = calloc (1, sizeof (chan));
ch = g_new0 (chan, 1);
ch->userdata = userdata;
ch->family = family;
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);
if (new_name != name)
free (new_name);
g_free (new_name);
return ret;
}
@ -492,7 +491,7 @@ chan_rename (chan *ch, char *name, int trunc_len)
ch->cv->trunc_len = trunc_len;
if (new_name != name)
free (new_name);
g_free (new_name);
}
/* this thing is overly complicated */
@ -645,7 +644,7 @@ chan_remove (chan *ch, gboolean force)
ch->cv->size--;
gtk_tree_store_remove (ch->cv->store, &ch->iter);
free (ch);
g_free (ch);
return TRUE;
}

View File

@ -727,7 +727,7 @@ custom_list_resort (CustomList * custom_list)
custom_list);
/* 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--)
{
@ -744,7 +744,7 @@ custom_list_resort (CustomList * custom_list)
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (custom_list), path, NULL,
neworder);
gtk_tree_path_free (path);
free (neworder);
g_free (neworder);
}
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);
else
{
free (mdc->nick);
free (mdc);
g_free (mdc->nick);
g_free (mdc);
}
}
void
fe_dcc_send_filereq (struct session *sess, char *nick, int maxcps, int passive)
{
char tbuf[128];
struct my_dcc_send *mdc;
char* tbuf = g_strdup_printf (_("Send file to %s"), nick);
mdc = malloc (sizeof (*mdc));
struct my_dcc_send *mdc = g_new (struct my_dcc_send, 1);
mdc->sess = sess;
mdc->nick = strdup (nick);
mdc->nick = g_strdup (nick);
mdc->maxcps = maxcps;
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);
g_free (tbuf);
}
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 */
/* of the exe. */
{
char *tmp = strdup (argv[0]);
char *tmp = g_strdup (argv[0]);
char *sl;
sl = strrchr (tmp, G_DIR_SEPARATOR);
@ -233,7 +233,7 @@ fe_args (int argc, char *argv[])
*sl = 0;
chdir (tmp);
}
free (tmp);
g_free (tmp);
}
#endif
@ -424,8 +424,7 @@ fe_new_window (session *sess, int focus)
void
fe_new_server (struct server *serv)
{
serv->gui = malloc (sizeof (struct server_gui));
memset (serv->gui, 0, sizeof (struct server_gui));
serv->gui = g_new0 (struct server_gui, 1);
}
void
@ -510,18 +509,15 @@ fe_set_topic (session *sess, char *topic, char *stripped_topic)
}
else
{
if (sess->res->topic_text)
{
free (sess->res->topic_text);
}
g_free (sess->res->topic_text);
if (prefs.hex_text_stripcolor_topic)
{
sess->res->topic_text = strdup (stripped_topic);
sess->res->topic_text = g_strdup (stripped_topic);
}
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 (*text)
free (*text);
*text = strdup (new_text);
g_free (*text);
*text = g_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_flags = flags;
lbuf->search_text = strdup (sstr);
lbuf->search_text = g_strdup (sstr);
gtk_xtext_lastlog (lbuf, buf);
}
@ -761,9 +756,8 @@ fe_set_lag (server *serv, long lag)
sess = list->data;
if (sess->server == serv)
{
if (sess->res->lag_tip)
free (sess->res->lag_tip);
sess->res->lag_tip = strdup (lagtip);
g_free (sess->res->lag_tip);
sess->res->lag_tip = g_strdup (lagtip);
if (!sess->gui->is_tab || current_tab == sess)
{
@ -777,9 +771,8 @@ fe_set_lag (server *serv, long lag)
} else
{
sess->res->lag_value = per;
if (sess->res->lag_text)
free (sess->res->lag_text);
sess->res->lag_text = strdup (lagtext);
g_free (sess->res->lag_text);
sess->res->lag_text = g_strdup (lagtext);
}
}
list = list->next;
@ -807,9 +800,8 @@ fe_set_throttle (server *serv)
snprintf (tbuf, sizeof (tbuf) - 1, _("%d bytes"), serv->sendq_len);
snprintf (tip, sizeof (tip) - 1, _("Network send queue: %d bytes"), serv->sendq_len);
if (sess->res->queue_tip)
free (sess->res->queue_tip);
sess->res->queue_tip = strdup (tip);
g_free (sess->res->queue_tip);
sess->res->queue_tip = g_strdup (tip);
if (!sess->gui->is_tab || current_tab == sess)
{
@ -823,9 +815,8 @@ fe_set_throttle (server *serv)
} else
{
sess->res->queue_value = per;
if (sess->res->queue_text)
free (sess->res->queue_text);
sess->res->queue_text = strdup (tbuf);
g_free (sess->res->queue_text);
sess->res->queue_text = g_strdup (tbuf);
}
}
list = list->next;
@ -977,9 +968,8 @@ fe_set_inputbox_contents (session *sess, char *text)
SPELL_ENTRY_SET_TEXT (sess->gui->input_box, text);
} else
{
if (sess->res->input_text)
free (sess->res->input_text);
sess->res->input_text = strdup (text);
g_free (sess->res->input_text);
sess->res->input_text = g_strdup (text);
}
}

View File

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

View File

@ -62,7 +62,7 @@ static void
gtkutil_file_req_destroy (GtkWidget * wid, struct file_req *freq)
{
freq->callback (freq->userdata, NULL);
free (freq);
g_free (freq);
}
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);
freq = malloc (sizeof (struct file_req));
freq = g_new (struct file_req, 1);
freq->dialog = dialog;
freq->flags = flags;
freq->callback = callback;

View File

@ -312,7 +312,7 @@ mg_inputbox_cb (GtkWidget *igad, session_gui *gui)
if (cmd[0] == 0)
return;
cmd = strdup (cmd);
cmd = g_strdup (cmd);
/* avoid recursive loop */
ignore = TRUE;
@ -340,7 +340,7 @@ mg_inputbox_cb (GtkWidget *igad, session_gui *gui)
if (sess)
handle_multiline (sess, cmd, TRUE, FALSE);
free (cmd);
g_free (cmd);
}
static gboolean
@ -609,14 +609,14 @@ mg_unpopulate (session *sess)
gui = sess->gui;
res = sess->res;
res->input_text = strdup (SPELL_ENTRY_GET_TEXT (gui->input_box));
res->topic_text = strdup (gtk_entry_get_text (GTK_ENTRY (gui->topic_entry)));
res->limit_text = strdup (gtk_entry_get_text (GTK_ENTRY (gui->limit_entry)));
res->key_text = strdup (gtk_entry_get_text (GTK_ENTRY (gui->key_entry)));
res->input_text = g_strdup (SPELL_ENTRY_GET_TEXT (gui->input_box));
res->topic_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (gui->topic_entry)));
res->limit_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (gui->limit_entry)));
res->key_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (gui->key_entry)));
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)
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++)
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)
{
gtk_label_set_text (GTK_LABEL (label), *text);
free (*text);
g_free (*text);
*text = NULL;
} else
{
@ -659,7 +659,7 @@ mg_restore_entry (GtkWidget *entry, char **text)
if (*text)
{
gtk_entry_set_text (GTK_ENTRY (entry), *text);
free (*text);
g_free (*text);
*text = NULL;
} else
{
@ -674,7 +674,7 @@ mg_restore_speller (GtkWidget *entry, char **text)
if (*text)
{
SPELL_ENTRY_SET_TEXT (entry, *text);
free (*text);
g_free (*text);
*text = NULL;
} else
{
@ -1331,8 +1331,7 @@ mg_close_gen (chan *ch, GtkWidget *box)
{
char *title = g_object_get_data (G_OBJECT (box), "title");
if (title)
free (title);
g_free (title);
if (!ch)
ch = g_object_get_data (G_OBJECT (box), "ch");
if (ch)
@ -1640,7 +1639,7 @@ mg_dnd_drop_file (session *sess, char *target, char *uri)
{
char *p, *data, *next, *fname;
p = data = strdup (uri);
p = data = g_strdup (uri);
while (*p)
{
next = strchr (p, '\r');
@ -1667,7 +1666,7 @@ mg_dnd_drop_file (session *sess, char *target, char *uri)
if (*p == '\n')
p++;
}
free (data);
g_free (data);
}
@ -1837,7 +1836,7 @@ mg_changui_destroy (session *sess)
/* it fixes: Gdk-CRITICAL **: gdk_colormap_get_screen: */
/* assertion `GDK_IS_COLORMAP (cmap)' failed */
ret = sess->gui->window;
free (sess->gui);
g_free (sess->gui);
sess->gui = NULL;
}
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);
chan_set_color (ch, plain_list);
/* 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);
if (prefs.hex_gui_tab_newtofront)
@ -3395,7 +3394,7 @@ fe_clear_channel (session *sess)
{
if (sess->res->topic_text)
{
free (sess->res->topic_text);
g_free (sess->res->topic_text);
sess->res->topic_text = NULL;
}
}
@ -3508,24 +3507,24 @@ mg_changui_new (session *sess, restore_gui *res, int tab, int focus)
session_gui *gui;
struct User *user = NULL;
if (!res)
if (res == NULL)
{
res = malloc (sizeof (restore_gui));
memset (res, 0, sizeof (restore_gui));
res = g_new0 (restore_gui, 1);
}
sess->res = res;
if (!sess->server->front_session)
if (sess->server->front_session == NULL)
{
sess->server->front_session = sess;
}
if (!is_channel (sess->server, sess->channel))
user = userlist_find_global (sess->server, sess->channel);
if (!tab)
{
gui = malloc (sizeof (session_gui));
memset (gui, 0, sizeof (session_gui));
gui = g_new0 (session_gui, 1);
gui->is_tab = FALSE;
sess->gui = gui;
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");
if (old)
{
g_object_set_data (G_OBJECT (vbox), "title", strdup (title));
free (old);
g_object_set_data (G_OBJECT (vbox), "title", g_strdup (title));
g_free (old);
} else
{
gtk_window_set_title (GTK_WINDOW (vbox), title);
@ -3650,7 +3649,7 @@ fe_server_callback (server *serv)
if (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 */
@ -3661,34 +3660,21 @@ fe_session_callback (session *sess)
if (sess->res->banlist && sess->res->banlist->window)
mg_close_gen (NULL, sess->res->banlist->window);
if (sess->res->input_text)
free (sess->res->input_text);
if (sess->res->topic_text)
free (sess->res->topic_text);
if (sess->res->limit_text)
free (sess->res->limit_text);
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);
g_free (sess->res->input_text);
g_free (sess->res->topic_text);
g_free (sess->res->limit_text);
g_free (sess->res->key_text);
g_free (sess->res->queue_text);
g_free (sess->res->queue_tip);
g_free (sess->res->lag_text);
g_free (sess->res->lag_tip);
if (sess->gui->bartag)
fe_timeout_remove (sess->gui->bartag);
if (sess->gui != &static_mg_gui)
free (sess->gui);
free (sess->res);
g_free (sess->gui);
g_free (sess->res);
}
/* ===== 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 */
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, "",
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);
free (buf);
g_free (buf);
}
/* userlist button has been clicked */
@ -166,11 +166,12 @@ userlist_button_cb (GtkWidget * button, char *cmd)
if (sess->type == SESS_DIALOG)
{
/* fake a selection */
nicks = malloc (sizeof (char *) * 2);
nicks = g_new (char *, 2);
nicks[0] = g_strdup (sess->channel);
nicks[1] = NULL;
num_sel = 1;
} else
}
else
{
/* find number of selected rows */
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, "", "");
if (nicks)
free (nicks);
g_free (nicks);
return;
}
}
/* create "allnicks" string */
allnicks = malloc (((NICKLEN + 1) * num_sel) + 1);
allnicks = g_malloc (((NICKLEN + 1) * num_sel) + 1);
*allnicks = 0;
i = 0;
@ -218,8 +218,8 @@ userlist_button_cb (GtkWidget * button, char *cmd)
g_free (nicks[num_sel]);
}
free (nicks);
free (allnicks);
g_free (nicks);
g_free (allnicks);
}
/* 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;
GtkWidget *submenu, *menu = gtk_menu_new ();
if (str_copy)
free (str_copy);
str_copy = strdup (nick);
g_free (str_copy);
str_copy = g_strdup (nick);
submenu_list = 0; /* first time through, might not be 0 */
@ -946,20 +945,19 @@ menu_urlmenu (GdkEventButton *event, char *url)
GtkWidget *menu;
char *tmp, *chop;
if (str_copy)
free (str_copy);
str_copy = strdup (url);
g_free (str_copy);
str_copy = g_strdup (url);
menu = gtk_menu_new ();
/* more than 51 chars? Chop it */
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[0] = chop[1] = chop[2] = '.';
chop[3] = 0;
menu_quick_item (0, tmp, menu, XCMENU_SHADED, 0, 0);
free (tmp);
g_free (tmp);
} else
{
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))
is_joined = TRUE;
if (str_copy)
free (str_copy);
str_copy = strdup (chan);
g_free (str_copy);
str_copy = g_strdup (chan);
menu = gtk_menu_new ();
@ -1072,9 +1069,8 @@ menu_addfavoritemenu (server *serv, GtkWidget *menu, char *channel, gboolean ist
if (channel != str_copy)
{
if (str_copy)
free (str_copy);
str_copy = strdup (channel);
g_free (str_copy);
str_copy = g_strdup (channel);
}
if (istree)

View File

@ -106,7 +106,7 @@ palette_alloc (GtkWidget * widget)
void
palette_load (void)
{
int i, j, l, fh;
int i, j, fh;
char prefname[256];
struct stat st;
char *cfg;
@ -116,35 +116,29 @@ palette_load (void)
if (fh != -1)
{
fstat (fh, &st);
cfg = malloc (st.st_size + 1);
if (cfg)
cfg = g_malloc0 (st.st_size + 1);
read (fh, cfg, st.st_size);
/* mIRC colors 0-31 are here */
for (i = 0; i < 32; i++)
{
cfg[0] = '\0';
l = read (fh, cfg, st.st_size);
if (l >= 0)
cfg[l] = '\0';
/* mIRC colors 0-31 are here */
for (i = 0; i < 32; i++)
{
snprintf (prefname, sizeof prefname, "color_%d", i);
cfg_get_color (cfg, prefname, &red, &green, &blue);
colors[i].red = red;
colors[i].green = green;
colors[i].blue = blue;
}
/* our special colors are mapped at 256+ */
for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
{
snprintf (prefname, sizeof prefname, "color_%d", i);
cfg_get_color (cfg, prefname, &red, &green, &blue);
colors[j].red = red;
colors[j].green = green;
colors[j].blue = blue;
}
free (cfg);
snprintf (prefname, sizeof prefname, "color_%d", i);
cfg_get_color (cfg, prefname, &red, &green, &blue);
colors[i].red = red;
colors[i].green = green;
colors[i].blue = blue;
}
/* our special colors are mapped at 256+ */
for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
{
snprintf (prefname, sizeof prefname, "color_%d", i);
cfg_get_color (cfg, prefname, &red, &green, &blue);
colors[j].red = red;
colors[j].green = green;
colors[j].blue = blue;
}
g_free (cfg);
close (fh);
}
}

View File

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

View File

@ -497,7 +497,7 @@ servlist_addnet_cb (GtkWidget *item, GtkTreeView *treeview)
ircnet *net;
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");
store = (GtkListStore *)gtk_tree_view_get_model (treeview);
@ -668,13 +668,12 @@ servlist_favor (GtkWidget *button, gpointer none)
static void
servlist_update_from_entry (char **str, GtkWidget *entry)
{
if (*str)
free (*str);
g_free (*str);
if (gtk_entry_get_text (GTK_ENTRY (entry))[0] == 0)
*str = NULL;
else
*str = strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
*str = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
}
static void
@ -1203,9 +1202,9 @@ servlist_celledit_cb (GtkCellRendererText *cell, gchar *arg1, gchar *arg2,
}
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);
free (netname);
g_free (netname);
}
gtk_tree_path_free (path);
@ -1311,7 +1310,7 @@ servlist_sanitize_hostname (char *host)
{
char *ret, *c, *e;
ret = strdup (host);
ret = g_strdup (host);
c = strchr (ret, ':');
e = strrchr (ret, ':');
@ -1371,7 +1370,7 @@ servlist_editserver_cb (GtkCellRendererText *cell, gchar *name, gchar *newval, g
servname = serv->hostname;
serv->hostname = servlist_sanitize_hostname (newval);
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;
entry->command = servlist_sanitize_command (newval);
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)
return;
if (selected_net->encoding)
free (selected_net->encoding);
selected_net->encoding = strdup (gtk_entry_get_text (entry));
g_free (selected_net->encoding);
selected_net->encoding = g_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. */

View File

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

View File

@ -292,7 +292,7 @@ insert_hiddenchar (SexySpellEntry *entry, guint start, guint end)
* is 'hidden' */
#if 0
PangoAttribute *hattr;
PangoRectangle *rect = g_malloc (sizeof (PangoRectangle));
PangoRectangle *rect = g_new (PangoRectangle, 1);
rect->x = 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);
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);
g_free (stamp);
memcpy (new_text + stamp_size, text, len);
gtk_xtext_append (xtbuf, new_text, len + stamp_size, timet);
free (new_text);
g_free (new_text);
} else
gtk_xtext_append (xtbuf, text, len, timet);
return;
@ -173,13 +173,12 @@ pevent_edited (GtkCellRendererText *render, gchar *pathstr, gchar *new_text, gpo
}
if (m > (te[sig].num_args & 0x7f))
{
free (out);
out = malloc (4096);
snprintf (out, 4096,
_("This signal is only passed %d args, $%d is invalid"),
te[sig].num_args & 0x7f, m);
g_free (out);
out = g_strdup_printf (
_("This signal is only passed %d args, $%d is invalid"),
te[sig].num_args & 0x7f, m);
fe_message (out, FE_MSG_WARN);
free (out);
g_free (out);
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_tree_path_free (path);
if (pntevts_text[sig])
free (pntevts_text[sig]);
if (pntevts[sig])
free (pntevts[sig]);
g_free (pntevts_text[sig]);
g_free (pntevts[sig]);
pntevts_text[sig] = malloc (len + 1);
memcpy (pntevts_text[sig], text, len + 1);
pntevts_text[sig] = g_strdup (text);
pntevts[sig] = out;
out = malloc (len + 2);
out = g_malloc (len + 2);
memcpy (out, text, len + 1);
out[len] = '\n';
out[len + 1] = 0;
check_special_chars (out, TRUE);
PrintTextRaw (xtext->buffer, out, 0, 0);
free (out);
g_free (out);
/* Scroll to bottom */
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]);
len = strlen (text);
out = malloc (len + 2);
out = g_malloc (len + 2);
memcpy (out, text, len + 1);
out[len] = '\n';
out[len + 1] = 0;
check_special_chars (out, TRUE);
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)
return NULL;
nicks = malloc (sizeof (char *) * (num_sel + 1));
nicks = g_new (char *, num_sel + 1);
i = 0;
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;
if (!prefs.hex_gui_ulist_icons)
{
nick = malloc (strlen (newuser->nick) + 2);
nick = g_malloc (strlen (newuser->nick) + 2);
nick[0] = newuser->prefix[0];
if (!nick[0] || nick[0] == ' ')
if (nick[0] == '\0' || nick[0] == ' ')
strcpy (nick, newuser->nick);
else
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)
{
free (nick);
g_free (nick);
}
/* is it me? */
@ -525,7 +525,7 @@ userlist_click_cb (GtkWidget *widget, GdkEventButton *event, gpointer userdata)
i--;
g_free (nicks[i]);
}
free (nicks);
g_free (nicks);
}
return TRUE;
}
@ -542,13 +542,13 @@ userlist_click_cb (GtkWidget *widget, GdkEventButton *event, gpointer userdata)
i--;
g_free (nicks[i]);
}
free (nicks);
g_free (nicks);
return TRUE;
}
if (nicks)
{
g_free (nicks[0]);
free (nicks);
g_free (nicks);
}
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
@ -567,7 +567,7 @@ userlist_click_cb (GtkWidget *widget, GdkEventButton *event, gpointer userdata)
i--;
g_free (nicks[i]);
}
free (nicks);
g_free (nicks);
}
} 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;
}
@ -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);
}
free (str);
g_free (str);
}
}
@ -2111,7 +2111,7 @@ gtk_xtext_selection_get_text (GtkXText *xtext, int *len_ret)
return NULL;
/* now allocate mem and copy buffer */
pos = txt = malloc (len);
pos = txt = g_malloc (len);
ent = buf->last_ent_start;
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 = txt;
len = strlen (txt);
} else
}
else
{
stripped = gtk_xtext_strip_color (txt, strlen (txt), NULL, &len, NULL, FALSE);
free (txt);
g_free (txt);
}
*len_ret = len;
@ -2209,7 +2210,7 @@ gtk_xtext_selection_get (GtkWidget * widget,
g_free (new_text);
}
free (stripped);
g_free (stripped);
}
static gboolean
@ -2364,7 +2365,7 @@ xtext_do_chunk(chunk_t *c)
if (c->len1 == 0)
return;
meta = malloc (sizeof *meta);
meta = g_new (offlen_t, 1);
meta->off = c->off1;
meta->len = c->len1;
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 */
if (outbuf == NULL)
new_str = malloc (len + 2);
new_str = g_malloc (len + 2);
else
new_str = outbuf;
@ -2463,7 +2464,7 @@ bad_utf8: /* Normal ending sequence, and give up if bad utf8 */
if (slpp)
*slpp = c.slp;
else
g_slist_free_full (c.slp, free);
g_slist_free_full (c.slp, g_free);
return new_str;
}
@ -2479,7 +2480,7 @@ gtk_xtext_text_width_ent (GtkXText *xtext, textentry *ent)
if (ent->slp)
{
g_slist_free_full (ent->slp, free);
g_slist_free_full (ent->slp, g_free);
ent->slp = NULL;
}
@ -2511,7 +2512,7 @@ gtk_xtext_text_width (GtkXText *xtext, unsigned char *text, int len)
&new_len, &slp, !xtext->ignore_hidden);
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;
}
@ -3534,7 +3535,7 @@ gtk_xtext_save (GtkXText * xtext, int fh)
&newlen, NULL, FALSE);
write (fh, buf, newlen);
write (fh, "\n", 1);
free (buf);
g_free (buf);
ent = ent->next;
}
}
@ -3899,10 +3900,10 @@ gtk_xtext_kill_ent (xtext_buffer *buffer, textentry *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);
free (ent);
g_free (ent);
return visible;
}
@ -4037,7 +4038,7 @@ gtk_xtext_clear (xtext_buffer *buf, int lines)
while (buf->text_first)
{
next = buf->text_first->next;
free (buf->text_first);
g_free (buf->text_first);
buf->text_first = next;
}
buf->text_last = NULL;
@ -4214,7 +4215,7 @@ gtk_xtext_search_textentry (xtext_buffer *buf, textentry *ent)
}
/* Common processing --- */
g_slist_free_full (slp, free);
g_slist_free_full (slp, g_free);
return gl;
}
@ -4643,7 +4644,7 @@ gtk_xtext_append_indent (xtext_buffer *buf,
if (right_text[right_len-1] == '\n')
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);
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))
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_len = len;
if (len)
@ -4963,8 +4964,7 @@ gtk_xtext_buffer_new (GtkXText *xtext)
{
xtext_buffer *buf;
buf = malloc (sizeof (xtext_buffer));
memset (buf, 0, sizeof (xtext_buffer));
buf = g_new0 (xtext_buffer, 1);
buf->old_value = -1;
buf->xtext = xtext;
buf->scrollbar_down = TRUE;
@ -4994,9 +4994,9 @@ gtk_xtext_buffer_free (xtext_buffer *buf)
while (ent)
{
next = ent->next;
free (ent);
g_free (ent);
ent = next;
}
free (buf);
g_free (buf);
}

View File

@ -78,7 +78,6 @@ fe_new_window (struct session *sess, int focus)
{
char buf[512];
sess->gui = malloc (4);
current_sess = sess;
if (!sess->server->front_session)
@ -140,7 +139,7 @@ timecat (char *buf, time_t stamp)
/* Windows doesn't handle ANSI codes in cmd.exe, need to not display them */
#ifndef WIN32
/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
static const short colconv[] = { 0, 7, 4, 2, 1, 3, 5, 11, 13, 12, 6, 16, 14, 15, 10, 7 };
void
@ -151,7 +150,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
char num[8];
int reverse = 0, under = 0, bold = 0,
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)
{
@ -308,7 +307,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
newtext[j] = 0;
write (STDOUT_FILENO, newtext, j);
free (newtext);
g_free (newtext);
}
#else
/* 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 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)
{
@ -403,7 +402,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp,
newtext[j] = 0;
write (STDOUT_FILENO, newtext, j);
free (newtext);
g_free (newtext);
}
#endif
@ -508,14 +507,14 @@ fe_args (int argc, char *argv[])
{
#ifdef WIN32
/* see the chdir() below */
char *sl, *exe = strdup (argv[0]);
char *sl, *exe = g_strdup (argv[0]);
sl = strrchr (exe, '\\');
if (sl)
{
*sl = 0;
printf ("%s\\plugins\n", exe);
}
free (exe);
g_free (exe);
#else
printf ("%s\n", HEXCHATLIBDIR);
#endif
@ -582,7 +581,6 @@ fe_exit (void)
void
fe_new_server (struct server *serv)
{
serv->gui = malloc (4);
}
void