diff options
author | TingPing <tingping@tingping.se> | 2014-12-28 06:37:25 -0500 |
---|---|---|
committer | TingPing <tingping@tingping.se> | 2014-12-28 06:44:44 -0500 |
commit | 83032b1aa3c3e5910c5cfd3e0ea1d25827f56475 (patch) | |
tree | 9be32a04d3070eac82177e11d182dad40a63baa7 /src/common/ignore.c | |
parent | c4cb1b25ec06a5b0cb718c6f8e74630df9a9bc64 (diff) |
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
Diffstat (limited to 'src/common/ignore.c')
-rw-r--r-- | src/common/ignore.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/common/ignore.c b/src/common/ignore.c index 045224ba..bfc6cf93 100644 --- a/src/common/ignore.c +++ b/src/common/ignore.c @@ -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); } |