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/fe-gtk/fkeys.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/fe-gtk/fkeys.c')
-rw-r--r-- | src/fe-gtk/fkeys.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/fe-gtk/fkeys.c b/src/fe-gtk/fkeys.c index 3c8745e7..66c98018 100644 --- a/src/fe-gtk/fkeys.c +++ b/src/fe-gtk/fkeys.c @@ -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; } |