[io-layer] Precise memcpy of handle structs.
First issue found by AddressSanitizer.