Fix memory leak when creating map field via array.

pull/4003/merge
Bo Yang 7 years ago
parent 1acacf46cc
commit b140cb3145
  1. 3
      php/ext/google/protobuf/type_check.c
  2. 5
      php/tests/memory_leak_test.php

@ -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); 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, 1);
RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 0);
} else if (Z_TYPE_P(val) == IS_OBJECT) { } else if (Z_TYPE_P(val) == IS_OBJECT) {
if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) { 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.", zend_error(E_USER_ERROR, "Given value is not an instance of %s.",

@ -110,6 +110,11 @@ $str_arr = array();
$m = new TestMessage(); $m = new TestMessage();
$m->setRepeatedString($str_arr); $m->setRepeatedString($str_arr);
// Test create map field via array.
$str_arr = array();
$m = new TestMessage();
$m->setMapStringString($str_arr);
# $from = new TestMessage(); # $from = new TestMessage();
# $to = new TestMessage(); # $to = new TestMessage();
# TestUtil::setTestMessage($from); # TestUtil::setTestMessage($from);

Loading…
Cancel
Save