You need to copy the buffer.
Count := Length(AData);
SetLength(buffer, Count);
if Count <> 0 then
Move(AData[0], buffer[0], Length(AData));
I have a feeling that this part of Indy was screwed up by Embarcadero. Note the dubious passing of array by value. If I recall, the version on Indy from the repo is better.