Fix crashes under Valgrind

* Fix crashes under valgrind when Zend MM is used;
* Double the number of preallocated frames (based on the longest
  execution path)
* More checks for the debug mode