Fixed bug #73964 (Segmentation fault (11))

This commit is contained in:
Xinchen Hui
2017-02-12 10:53:36 +08:00
parent 9be57325c6
commit 527f927ead
3 changed files with 53 additions and 2 deletions

7
lua.c
View File

@@ -174,6 +174,11 @@ static void php_lua_dtor_object(zend_object *object) /* {{{ */ {
php_lua_object *lua_obj = php_lua_obj_from_obj(object);
zend_object_std_dtor(&(lua_obj->obj));
}
/* }}} */
static void php_lua_free_object(zend_object *object) /* {{{ */ {
php_lua_object *lua_obj = php_lua_obj_from_obj(object);
if (lua_obj->L) {
lua_close(lua_obj->L);
@@ -831,7 +836,7 @@ PHP_MINIT_FUNCTION(lua) {
memcpy(&lua_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
lua_object_handlers.offset = XtOffsetOf(php_lua_object, obj);
lua_object_handlers.dtor_obj = php_lua_dtor_object;
lua_object_handlers.free_obj = NULL;
lua_object_handlers.free_obj = php_lua_free_object;
lua_object_handlers.clone_obj = NULL;
lua_object_handlers.write_property = php_lua_write_property;
lua_object_handlers.read_property = php_lua_read_property;

View File

@@ -35,7 +35,7 @@
</stability>
<license uri="http://www.php.net/license">PHP</license>
<notes>
- Fixed issue #20 (PHP 7: Lua::eval(): unsupported type `unknown' for lua)
- Fixed bug #73964 (Segmentation fault)
</notes>
<contents>
<dir name="/">
@@ -65,6 +65,7 @@
<file name="issue012.phpt" role="test" />
<file name="bug65097.phpt" role="test" />
<file name="bug71997.phpt" role="test" />
<file name="bug73964.phpt" role="test" />
</dir>
</dir>
</contents>

45
tests/bug73964.phpt Normal file
View File

@@ -0,0 +1,45 @@
--TEST--
Bug #73964 (Segmentation fault (11))
--SKIPIF--
<?php
if (!extension_loaded("lua")) print "skip lua extension missing";
?>
--FILE--
<?php
class LuaTest
{
function __construct()
{
$this->lua = new Lua();
$this->lua->registerCallback("log", array($this, "API_LuaLog"));
}
function API_LuaLog( $entry)
{
echo("from lua: $entry");
}
public function RunTest()
{
$this->lua->eval(<<<CODE
function TestFunc(str)
log(str)
end
CODE
);
$GamePackage = $this->lua->RootTable;
$this->lua->call("TestFunc", array("okey"));
}
}
$a = new LuaTest();
$a->runtest();
?>
--EXPECT--
from lua: okey