diff options
author | Bo Yang <teboring@google.com> | 2017-12-04 12:32:10 -0800 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2017-12-04 12:32:10 -0800 |
commit | b140cb3145f697a025d7b81b53a190d1e89b17dc (patch) | |
tree | 9af5d19c73692f7f926851490fc93484d7b41618 | |
parent | 1acacf46ccd386de8ee660335b4b1a8dffb2967d (diff) | |
download | protobuf-b140cb3145f697a025d7b81b53a190d1e89b17dc.tar.gz protobuf-b140cb3145f697a025d7b81b53a190d1e89b17dc.tar.bz2 protobuf-b140cb3145f697a025d7b81b53a190d1e89b17dc.zip |
Fix memory leak when creating map field via array.
-rw-r--r-- | php/ext/google/protobuf/type_check.c | 3 | ||||
-rw-r--r-- | php/tests/memory_leak_test.php | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index 50e0f8c1..37171426 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -534,8 +534,7 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type, CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)value) TSRMLS_CC); } - Z_DELREF_P(CACHED_TO_ZVAL_PTR(map_field)); - RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 0); + RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 1); } else if (Z_TYPE_P(val) == IS_OBJECT) { if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) { zend_error(E_USER_ERROR, "Given value is not an instance of %s.", diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index fa272b56..772b466f 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -110,6 +110,11 @@ $str_arr = array(); $m = new TestMessage(); $m->setRepeatedString($str_arr); +// Test create map field via array. +$str_arr = array(); +$m = new TestMessage(); +$m->setMapStringString($str_arr); + # $from = new TestMessage(); # $to = new TestMessage(); # TestUtil::setTestMessage($from); |