more fixes and extending the tests coverage bunch of cleanups and 2 leaks

* gentest.py testapi.c: more fixes and extending the tests coverage
* valid.c: bunch of cleanups and 2 leaks removed
Daniel
4 files changed