Each -printf invocation created a memstream, then freed the underlying
buffer without closing the stream, resulting in a segfault on exit
when libc tried to flush all the streams.
Furthermore:
* Change escape() to return char * instead of const char *
* Simplify the implementation of %h
* Fix %M, which printed an extra space
* Implement %l correctly
* Implement %Y and %y
* Add tests for everything except %S
Fixes: 7b9c912c41f4