From a7927d1dba01769af1869e7e4a704f38e9600759 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sat, 21 Feb 2015 18:28:58 +0100 Subject: fixed memory leak in classimpl --- zend/classimpl.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'zend/classimpl.cpp') diff --git a/zend/classimpl.cpp b/zend/classimpl.cpp index ab95455..82cbc66 100644 --- a/zend/classimpl.cpp +++ b/zend/classimpl.cpp @@ -20,6 +20,11 @@ ClassImpl::~ClassImpl() { // destruct the entries if (_entries) delete[] _entries; + +#if PHP_VERSION_ID >= 50400 + // on newer php versions, we have allocated the command to hide a pointer in it + if (_self) free(_self); +#endif } /** @@ -1419,16 +1424,16 @@ zend_class_entry *ClassImpl::initialize(ClassBase *base, const std::string &pref #if PHP_VERSION_ID >= 50400 // allocate doc comment to contain an empty string + a hidden pointer - char *_comment = (char *)malloc(1 + sizeof(ClassImpl *)); + _self = (char *)malloc(1 + sizeof(ClassImpl *)); // empty string on first position - _comment[0] = '\0'; + _self[0] = '\0'; // copy the 'this' pointer to the doc-comment - memcpy(_comment+1, &impl, sizeof(ClassImpl *)); + memcpy(_self+1, &impl, sizeof(ClassImpl *)); // set our comment in the actual class entry - _entry->info.user.doc_comment = _comment; + _entry->info.user.doc_comment = _self; #else -- cgit v1.2.3