Do we always reallocate to larger size? It is currently reallocated based on the actual message size returned by the server, while buffer_size in peek_message may be bigger (and it is first allocated to 1024 bytes). Granted, I only reproduced the actual memory corruption with Proton, but it seems to me that in this regard the handling is the same.