MemoryOutputStream to MemoryBlock issue

I was using the URL class and noticed that my post data is corrupt. After some debugging I realized URLHelpers::createHeadersAndPostData is using a MemoryOutputStream to insert the mangled parameters and post data into the postData MemoryBlock.

The MemoryBlock did contain the parameters and data, but it also contained some weird suffix, 

ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍýýýý««««««««îþîþ

I read the documentation and tried to use a MemoryOutputStream::flush() before and after the writes, and it just reduced the suffix to

ýýýý««««««««ÍÍÍÍ

I'm guessing the leftover suffix is the reminder of the last allocated block, which was not fully utilized.

 

Am I doing something wrong here?

 

 

The code in the URL class all looks correct to me. If you're using the new withDataToUpload method then you're probably giving it a dodgy block of memory to upload?