os_stream: fix bugs in allocation path