buffer is too small (based on a patch by Aric Stewart) - add a test case to show correct behaviour
- fix memory leaks