summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-02-21 18:28:58 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-02-21 18:28:58 +0100
commita7927d1dba01769af1869e7e4a704f38e9600759 (patch)
tree1bc86f027e3e71b20984a599e14f00353178370f
parente1f97c494ae31b9d67e85c6b17a18bb925bc2989 (diff)
fixed memory leak in classimpl
-rw-r--r--zend/classimpl.cpp13
-rw-r--r--zend/classimpl.h9
2 files changed, 16 insertions, 6 deletions
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
diff --git a/zend/classimpl.h b/zend/classimpl.h
index 32f0e1f..5d0ab60 100644
--- a/zend/classimpl.h
+++ b/zend/classimpl.h
@@ -42,13 +42,13 @@ private:
* @var zend_class_entry
*/
zend_class_entry *_entry = nullptr;
-
+
/**
* Pointer to the entries
* @var zend_function_entry[]
*/
zend_function_entry *_entries = nullptr;
-
+
/**
* All class methods
* @var std::list
@@ -91,6 +91,11 @@ private:
*/
bool _initialized = false;
+ /**
+ * Memory allocated by this object to hide a pointer
+ * @var char*
+ */
+ char *_self = nullptr;
/**
* Retrieve an array of zend_function_entry objects that hold the