From 20abe78848cd3839b1f6412cec612429ff8c4269 Mon Sep 17 00:00:00 2001 From: Timandes White Date: Tue, 22 Jan 2019 10:06:44 +0800 Subject: [PATCH] fix: try to fix GH PR #31 --- ChangeLog | 1 + php_zookeeper.c | 3 +-- tests/gh-pr-31.phpt | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/gh-pr-31.phpt diff --git a/ChangeLog b/ChangeLog index 2d46948..26652fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ Version 0.6.3 Bugs: * Correct exception message (From "Failed to connect to Zookeeper" to "Failed to initialize ZooKeeper ...", Issue #29) * Fix 'duplicate symbol _php_zk_config_ce' + * Fix segmentation fault when destroying Zookeeper instance (GH PR #31) Version 0.6.2 ------------- diff --git a/php_zookeeper.c b/php_zookeeper.c index 2be3b33..7562201 100644 --- a/php_zookeeper.c +++ b/php_zookeeper.c @@ -884,9 +884,8 @@ zend_object* php_zk_new(zend_class_entry *ce TSRMLS_DC) { php_zk_t *i_obj; - i_obj = ecalloc(1, sizeof(*i_obj)); + i_obj = ecalloc(1, sizeof(php_zk_t) + zend_object_properties_size(ce)); zend_object_std_init( &i_obj->zo, ce TSRMLS_CC ); - object_properties_init(&i_obj->zo, ce); i_obj->zo.handlers = &zookeeper_obj_handlers; zend_hash_init_ex(&i_obj->callbacks, 5, NULL, (dtor_func_t)php_cb_data_zv_destroy, 0, 0); diff --git a/tests/gh-pr-31.phpt b/tests/gh-pr-31.phpt new file mode 100644 index 0000000..c56e5a4 --- /dev/null +++ b/tests/gh-pr-31.phpt @@ -0,0 +1,28 @@ +--TEST-- +php-zookeeper/php-zookeeper's PR #31 +--SKIPIF-- + +--FILE-- +create( + $key, + '', + [[ 'perms' => \Zookeeper::PERM_ALL, 'scheme' => 'world', 'id' => 'anyone' ]], + \Zookeeper::EPHEMERAL + ); +} + +create('/' . uniqid()); +create('/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' . uniqid()); + +echo 'OK'; + +--EXPECT-- +OK