In a PHP extension, what is the difference between this:
PHP_METHOD(TestExtension, test)
{
MyClass *myclass;
MyClass_Object *obj = (MyClass_Object*)zend_object_store_get_object(getThis() TSRMLS_CC);
myclass = obj->myclass;
if (myclass != NULL)
{
string retval = myclass->test();
RETURN_STRING(retval.c_str(), 1);
}
RETURN_NULL();
}
and this:
PHP_METHOD(TestExtension, test)
{
MyClass *myclass;
MyClass_Object *obj = (MyClass_Object*)zend_object_store_get_object(getThis() TSRMLS_CC);
myclass = obj->myclass;
if (myclass != NULL)
{
RETURN_STRING(myclass->test().c_str(), 1);
}
RETURN_NULL();
}
?
Both seem to work, but when I run valgrind with:
valgrind --tool=memcheck --num-callers=30 --log-file=./php.log /usr/bin/php test.php
where test.php is:
<?php
$obj = new TestExtension("testing");
echo $obj->test() . "\n";
?>
then the latter gives me a whole bunch of errors, all of which are:
Address 0xe4c3e98 is 24 bytes inside a block of size 66 free'd
The valgrind summary is as follows:
126 ==23067== HEAP SUMMARY:
127 ==23067== in use at exit: 9,031 bytes in 15 blocks
128 ==23067== total heap usage: 25,131 allocs, 25,116 frees, 4,435,757 bytes allocated
129 ==23067==
130 ==23067== LEAK SUMMARY:
131 ==23067== definitely lost: 0 bytes in 0 blocks
132 ==23067== indirectly lost: 0 bytes in 0 blocks
133 ==23067== possibly lost: 0 bytes in 0 blocks
134 ==23067== still reachable: 9,031 bytes in 15 blocks
135 ==23067== suppressed: 0 bytes in 0 blocks
136 ==23067== Rerun with --leak-check=full to see details of leaked memory
137 ==23067==
138 ==23067== For counts of detected and suppressed errors, rerun with: -v
139 ==23067== ERROR SUMMARY: 48 errors from 5 contexts (suppressed: 0 from 0)