Fix several more memory leak

pull/4102/head
Bo Yang 7 years ago
parent 7d3437152a
commit 3b7a5f4515
  1. 1
      php/ext/google/protobuf/def.c
  2. 8
      php/ext/google/protobuf/message.c
  3. 1
      php/ext/google/protobuf/type_check.c
  4. 23
      php/tests/memory_leak_test.php

@ -249,6 +249,7 @@ PHP_METHOD(Descriptor, getField) {
MAKE_STD_ZVAL(field_hashtable_value);
ZVAL_OBJ(field_hashtable_value, field_descriptor_type->create_object(
field_descriptor_type TSRMLS_CC));
Z_DELREF_P(field_hashtable_value);
#else
field_hashtable_value =
field_descriptor_type->create_object(field_descriptor_type TSRMLS_CC);

@ -374,7 +374,7 @@ PHP_METHOD(Message, whichOneof) {
LOWER_FIELD) \
PHP_METHOD(UPPER_CLASS, get##UPPER_FIELD) { \
zval member; \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \
PHP_PROTO_FAKE_SCOPE_BEGIN(LOWER_CLASS##_type); \
zval* value = message_get_property_internal(getThis(), &member TSRMLS_CC); \
PHP_PROTO_FAKE_SCOPE_END; \
@ -387,7 +387,7 @@ PHP_METHOD(Message, whichOneof) {
return; \
} \
zval member; \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \
message_set_property_internal(getThis(), &member, value TSRMLS_CC); \
PHP_PROTO_RETVAL_ZVAL(getThis()); \
}
@ -396,7 +396,7 @@ PHP_METHOD(Message, whichOneof) {
LOWER_FIELD) \
PHP_METHOD(UPPER_CLASS, get##UPPER_FIELD) { \
zval member; \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \
PHP_PROTO_FAKE_SCOPE_BEGIN(LOWER_CLASS##_type); \
message_get_oneof_property_internal(getThis(), &member, \
return_value TSRMLS_CC); \
@ -409,7 +409,7 @@ PHP_METHOD(Message, whichOneof) {
return; \
} \
zval member; \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \
PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \
message_set_property_internal(getThis(), &member, value TSRMLS_CC); \
PHP_PROTO_RETVAL_ZVAL(getThis()); \
}

@ -532,6 +532,7 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type,
map_field_handlers->write_dimension(
CACHED_TO_ZVAL_PTR(map_field), &key,
CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)value) TSRMLS_CC);
zval_dtor(&key);
}
RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 1);

@ -106,15 +106,34 @@ $m->mergeFromString(hex2bin('F80601'));
assert('F80601', bin2hex($m->serializeToString()));
// Test create repeated field via array.
$str_arr = array();
$str_arr = array("abc");
$m = new TestMessage();
$m->setRepeatedString($str_arr);
// Test create map field via array.
$str_arr = array();
$str_arr = array("abc"=>"abc");
$m = new TestMessage();
$m->setMapStringString($str_arr);
// Test unset
$from = new TestMessage();
TestUtil::setTestMessage($from);
unset($from);
// Test wellknown
$from = new \Google\Protobuf\Timestamp();
$from->setSeconds(1);
assert(1, $from->getSeconds());
$from = new \Google\Protobuf\Value();
$from->setNumberValue(1);
assert(1, $from->getNumberValue());
// Test descriptor
$pool = \Google\Protobuf\DescriptorPool::getGeneratedPool();
$desc = $pool->getDescriptorByClassName("\Foo\TestMessage");
$field = $desc->getField(1);
# $from = new TestMessage();
# $to = new TestMessage();
# TestUtil::setTestMessage($from);

Loading…
Cancel
Save