Handle the case where allocations fail in C callbacks of stream.c.

This is a first step to fix #114. I can confirm that this fixes the issue described there for a server that runs out of memory. Writing a unit test for this case is rather tricky, though.