mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-10 07:50:19 +00:00
Use glib for all allocations
- Removes need to check for malloc failure - Removes need for NULL checks on free - Adds checks for integer overflows - Removes some extra memset calls - Removes chance of mixing libc and glib malloc/free
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user