Deduplicate macros, Fix memleak in PHP < 5.4

See #802, #910, #914

Bonus: free all allocated memory on fatal error *without* segmentation faults (should we backport this to 1.2.1?)