ZTS fixes.
Fix memory leaks
Segfault fix.
Fixed a number of memleaks and cleaned up the code a bit.
Adding the tidy extension to PECL
12345678910