Add a minimal test framework and a test revealing file descriptor leakage
Bug fix

- fix file descriptor leak
- fix occasional segfault
- some code reformatting
Bump version