aboutsummaryrefslogtreecommitdiffhomepage
path: root/php
diff options
context:
space:
mode:
authorGravatar Bo Yang <teboring@google.com>2017-12-01 20:14:19 -0800
committerGravatar Bo Yang <teboring@google.com>2017-12-01 20:14:57 -0800
commit1acacf46ccd386de8ee660335b4b1a8dffb2967d (patch)
treea2499d4b06538718d04e60ace6f29b4b87f830f1 /php
parent94bb1eed17209cacfdf2571be5a1ae91b3964cff (diff)
Fix memory leak when creating repeated field via array.
Diffstat (limited to 'php')
-rw-r--r--php/ext/google/protobuf/type_check.c3
-rw-r--r--php/tests/memory_leak_test.php5
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 f588774c..50e0f8c1 100644
--- a/php/ext/google/protobuf/type_check.c
+++ b/php/ext/google/protobuf/type_check.c
@@ -461,8 +461,7 @@ void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type,
CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC);
}
- Z_DELREF_P(CACHED_TO_ZVAL_PTR(repeated_field));
- RETURN_ZVAL(CACHED_TO_ZVAL_PTR(repeated_field), 1, 0);
+ RETURN_ZVAL(CACHED_TO_ZVAL_PTR(repeated_field), 1, 1);
} else if (Z_TYPE_P(val) == IS_OBJECT) {
if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) {
diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php
index b76c8bff..fa272b56 100644
--- a/php/tests/memory_leak_test.php
+++ b/php/tests/memory_leak_test.php
@@ -105,6 +105,11 @@ $m = new TestMessage();
$m->mergeFromString(hex2bin('F80601'));
assert('F80601', bin2hex($m->serializeToString()));
+// Test create repeated field via array.
+$str_arr = array();
+$m = new TestMessage();
+$m->setRepeatedString($str_arr);
+
# $from = new TestMessage();
# $to = new TestMessage();
# TestUtil::setTestMessage($from);