which looks like you're using some sentinel value as allocation size. Perhaps something has been filling the memory with 0x59 to indicate unintialized or freed regions. Double-check where the size comes from, and treat every unsafe related to it as very suspect.
Perhaps you're reading structure into uninitialized memory, and not checking if the buffer has been filled completely? For example, every use of read() instead of read_exact() is likely a bug (same for write() being a backstabbing bug-causing cousin of write_all()).