NOT new_charset = (struct t_charset *)malloc (sizeof (struct t_charset)); BUT new_charset = malloc (sizeof (*new_charset)); NOT ... length * sizeof (char) ... BUT ... length ...