While encoding the frame in ASCII mode, per component four bytes are needed and after every 20 bytes, a \n will be added. So the calculation should be size = size * (4 + 1 / 20). This should exclude the header being written. Since header is also being included in the calculations, memory mishandlings are happening. https://bugzilla.gnome.org/show_bug.cgi?id=759520