lisachenko / z-engine

:zap: PHP Engine Direct API
MIT License
448 stars 22 forks source link

Fix memory leak and heap corruption during trait manipulation #10

Closed lisachenko closed 4 years ago

lisachenko commented 4 years ago

This issue pretty same as #9, but relates to the traits. Receipt as previous: for internal classes we should use persistent memory, for user-defined non-persistent memory should be used.

Also, for user-defined classes previously allocated memory should be freed to prevent leaks.

lisachenko commented 4 years ago

Surprisingly, this patch is not so easy, as previous one. There are a lot of hell with releasing zend_class_name structure, because it contains two zend_string pointers and zend_string_release function is not exported, thus need to copy-paste all the logic to control the behavior of allocated strings to prevent memory leaks and segfaults.